链接: 原网站.
题目
It was the third month of remote learning, Nastya got sick of staying at dormitory, so she decided to return to her hometown. In order to make her trip more entertaining, one of Nastya’s friend presented her an integer array a.
Several hours after starting her journey home Nastya remembered about the present. To entertain herself she decided to check, are there four different indices x,y,z,w such that ax+ay=az+aw.
Her train has already arrived the destination, but she still hasn’t found the answer. Can you help her unravel the mystery?
Input
The first line contains the single integer n (4≤n≤200000) — the size of the array.
The second line contains n integers a1,a2,…,an (1≤ai≤2.5⋅106).
Output
Print “YES” if there are such four indices, and “NO” otherwise.
If such indices exist, print these indices x, y, z and w (1≤x,y,z,w≤n).
If there are multiple answers, print any of them.
Examples
input
6
2 1 5 2 7 4
output
YES
2 3 1 6
input
5
1 3 1 9 20
output
NO
Note
In the first example a2+a3=1+5=2+4=a1+a6. Note that there are other answer, for example, 2 3 4 6.
In the second example, we can’t choose four indices. The answer 1 2 2 3 is wrong, because indices should be different, despite that a1+a2=1+3=3+1=a2+a3
题解
暴力搜索,奇奇怪怪,可可爱爱
本来想着绝壁会TLE的,结果好像不会,emm…
说是因为啥抽屉原理的样子,等再学一下重新来补题解
AC代码
pair<int,int> b[maxn];
int a[maxn];
signed main() {
int n = rd();
for(int i=1; i<=n; i++)a[i]=rd();
for(int i=1; i<n; i++) {
for(int j=i+1; j<=n; j++) {
int sum=a[i]+a[j];//枚举结果
if(b[sum].first) {
if(b[sum].first!=i&&b[sum].second!=i&&b[sum].first!=j&&b[sum].second!=j) {//a!=b!=c!=d
printf("YES\n%lld %lld %lld %lld\n",b[sum].first,b[sum].second,i,j);
return 0;
}
} else b[sum]=make_pair(i,j);//成对
}
}
printf("NO\n");
return 0;
}