C. Going Home

原题链接:

(https://codeforces.com/contest/1501/problem/C)

原题:

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

题解:

题意中让找出某两个数相加等于另外两个数相加的数组中的四个数。
对于这题不难看出可以用pair来储存其中前两个数的和以及这两个数,
当这个和第一次出现时将其及其两个数储存在pair里面当再出现这个和时判断此时的i和j是否和之间储存的两个有重复的,如果都不重复则输出‘YES’再输出呢四个数,否则输出’NO‘。

代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#define N 200005 
#define M 5000000
using namespace std;
int n,a[N];
pair<int ,pair<int,int> > p[M];
int main()
{
	ios::sync_with_stdio(0);//使cin输入的速度更快。
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	for(int i=1;i<=n;i++)
		for(int j=i+1;j<=n;j++)
		{
			int x=a[i]+a[j];
			p[x].first++; 
			if(p[x].first==1)
				p[x].second.first=i , p[x].second.second=j;
			else 
			{
				int z=p[x].second.first, w=p[x].second.second;
				if(z!=i&&w!=i&&z!=j&&w!=j)
				{
					cout<<"YES\n"<<z<<" "<<w<<" "<<i<<" "<<j;
					return 0;
				}
			}	
		}
	cout<<"NO";
} 
 
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值