Codeforces Round #521 (Div. 3) C. Good Array

本文探讨了一种特殊数组——好数组的概念,其中至少存在一个元素等于数组其余所有元素之和。文章提出了一种算法,用于找出数组中哪些元素在移除后能使剩余数组变为好数组,并详细介绍了实现这一目标的代码示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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.

(PS):忽略了数据的大小,需要用long long,被hacked了呜呜~

题意:去掉任意一个数,使剩下的数的最大值等于其他n-2个数的和,输出满足题意的去掉的数的位置,以任意顺序输出。

分析:通过pair的第一个数表示输入的数的值,第二个数 表示输入的数的位置坐标。通过sort排序(pair默认的按照第一个数升序),然后分为两种情况。①前 n-1个数,去掉任意一个数,其他数的和等于第n个数的值。②特 判最后一个数,去掉最后一个数,判断前n-2项的和是否等于第n-1项的值。

代码:

#include <utility>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include<cstdio>
using namespace std;
typedef pair<long long int, long long int> P;
const int N =200008;
pair<long long int, long long int> items[N];
long long int b[200008];
int main()
{

    long long int n,maxn=0;
    scanf("%lld",&n);
    long long int sum=0;
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&items[i].first);
        items[i].second=i;
        sum+=items[i].first;
        maxn=max(items[i].first,maxn);
    }
    long long int j=0;
    sum-=maxn;
    sort(items,items+n+1);
    for(int i=1;i<n;i++)
    {
        if(sum-items[i].first==maxn)
        {
            b[++j]=items[i].second;
        }
    }
    if(sum==2*items[n-1].first) b[++j]=items[n].second;
    printf("%lld\n",j);
    for(int i=1;i<=j;i++)
    {
        printf("%lld ",b[i]);
    }
    return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

不会敲代码的小帅

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值