codeforce Round#521 C. Good Array

原题传送

C. Good Array

Let's call an array good if there is an element in the array that equals to the sum of all other elements. For example, the array a=[1,3,3,7]a=[1,3,3,7] is good because there is the element a4=7a4=7 which equals to the sum 1+3+31+3+3.

You are given an array aa consisting of nn integers. Your task is to print all indices jj of this array such that after removing the jj-th element from the array it will be good (let's call such indices nice).

For example, if a=[8,3,5,2]a=[8,3,5,2], the nice indices are 11 and 44:

  • if you remove a1a1, the array will look like [3,5,2][3,5,2] and it is good;
  • if you remove a4a4, the array will look like [8,3,5][8,3,5] and it is good.

You have to consider all removals independently, i. e. remove the element, check if the resulting array is good, and return the element into the array.

Input

The first line of the input contains one integer nn (2≤n≤2⋅1052≤n≤2⋅105) — the number of elements in the array aa.

The second line of the input contains nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤1061≤ai≤106) — elements of the array aa.

Output

In the first line print one integer kk — the number of indices jj of the array aa such that after removing the jj-th element from the array it will be good (i.e. print the number of the nice indices).

In the second line print kk distinct integers j1,j2,…,jkj1,j2,…,jk in any order — nice indices of the array aa.

If there are no such indices in the array aa, just print 00 in the first line and leave the second line empty or do not print it at all.

Examples

input

Copy

5
2 5 1 2 2

output

Copy

3
4 1 5

input

Copy

4
8 3 5 2

output

Copy

2
1 4 

input

Copy

5
2 1 2 4 3

output

Copy

0

Note

In the first example you can remove any element with the value 22 so the array will look like [5,1,2,2][5,1,2,2]. The sum of this array is 1010 and there is an element equals to the sum of remaining elements (5=1+2+25=1+2+2).

In the second example you can remove 88 so the array will look like [3,5,2][3,5,2]. The sum of this array is 1010 and there is an element equals to the sum of remaining elements (5=3+25=3+2). You can also remove 22 so the array will look like [8,3,5][8,3,5]. The sum of this array is 1616 and there is an element equals to the sum of remaining elements (8=3+58=3+5).

In the third example you cannot make the given array good by removing exactly one element.

题意:n个数删除其中一个数,使剩下的(n-1)个数中有一个数等于其他(n-2)个数之和。

思路:

除remove那个数之外的(n-1)部分,只有最大数才能等于其它(n-2)个数之和 

最大值的两种情况:

1,若remove的不是最大数,则(n-1)部分最大值为Max

2,remove的是最大数,则(n-1)部分最大值为所有数中第二大的数

AC代码:

#include<stdio.h>//思路:除remove的那个数之外剩余的部分,只有最大数才
#include<math.h>//		能等于其他数之和 
#include<string.h>
#include<algorithm>
const int maxn=2*1e5+7;//仅求最大值少用排序 !!!以及控制时间 
int a[maxn];
int main()
{
	int n;
	scanf("%d",&n);
	long long sum=0;
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		sum+=a[i];
	}
	int Max=0,flag;
    for(int i=1;i<=n;i++)
    {
    	if(a[i]>Max)
    	{
    		Max=a[i];
    		flag=i;
		}
	}
	a[flag]=0;//将最大的那个数置为0 ,为求第二大数 
	int Max2;//第二大的数 
	for(int i=1;i<=n;i++)
	{
		if(a[i]>Max2)
    	Max2=a[i];
	}
	a[flag]=Max; //还原 
	int ant=0;
	for(int i=1;i<=n;i++)
	{
		if(a[i]!=Max)//除了最大的那个数之外,剩余部分的最大的数都是Max 
		{
			if(sum-a[i]-Max==Max)
				ant++;
		 } 
		 else//判断去掉最大的那个数 
		 {
		 	if(sum-a[i]-Max2==Max2)
				ant++;
		 }
	 } 
	 printf("%d\n",ant);
	 if(ant!=0)
  {
	 for(int i=1;i<=n;i++)
	{
		if(a[i]!=Max)
		{
			if(sum-a[i]-Max==Max)
				printf("%d ",i);
		 } 
		 else//判断去掉最大的那个数 
		 {
		 	if(sum-a[i]-Max2==Max2)
				printf("%d ",i);
		 }
	 } 
	 printf("\n");
  }
	return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_42804678/article/details/84347356