CF1077C.Good Array

普及-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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=7a_4=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 a1a_1, the array will look like [3,5,2][3, 5, 2] and it is good;
  • if you remove a4a_4, 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.

我们称一个数组是“好的”,如果该数组中存在某个元素等于其余所有元素之和。例如,数组 a=[1,3,3,7]a=[1, 3, 3, 7] 是好的,因为其中存在元素 a4=7a_4=7,它等于 1+3+31 + 3 + 3。

给你一个由 nn 个整数组成的数组 aa。你的任务是输出该数组中所有满足如下条件的下标 jj(我们称这些下标为“优美的”):从数组中移除第 jj 个元素后,所得数组是“好的”。

例如,若 a=[8,3,5,2]a=[8, 3, 5, 2],则优美的下标为 11 和 44:

  • 若移除 a1a_1,数组变为 [3,5,2][3, 5, 2],它是好的;
  • 若移除 a4a_4,数组变为 [8,3,5][8, 3, 5],它是好的。

你必须独立地考虑每一次移除操作,即:移除该元素 → 检查所得数组是否为“好的” → 再将该元素放回原数组。

输入格式

The first line of the input contains one integer nn (2≤n≤2⋅1052 \le n \le 2 \cdot 10^5) — the number of elements in the array aa.

The second line of the input contains nn integers a1,a2,…,ana_1, a_2, \dots, a_n (1≤ai≤1061 \le a_i \le 10^6) — elements of the array aa.

输入的第一行包含一个整数 nn(2≤n≤2⋅1052 \le n \le 2 \cdot 10^5)—— 表示数组 aa 中的元素个数。

输入的第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \dots, a_n(1≤ai≤1061 \le a_i \le 10^6)—— 表示数组 aa 的元素。

输出格式

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,…,jkj_1, j_2, \dots, j_k 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.

第一行输出一个整数 kk —— 表示数组 aa 中满足如下条件的下标 jj 的个数:从数组中删除第 jj 个元素后,剩余数组是“好”的(即输出“好”下标的个数)。

第二行按任意顺序输出 kk 个互不相同的整数 j1,j2,…,jkj_1, j_2, \dots, j_k —— 即数组 aa 的所有“好”下标。

若数组 aa 中不存在这样的下标,则第一行仅输出 00,第二行留空或完全不输出。

输入输出样例

  • 输入#1

    5
    2 5 1 2 2

    输出#1

    3
    4 1 5
  • 输入#2

    4
    8 3 5 2

    输出#2

    2
    1 4
  • 输入#3

    5
    2 1 2 4 3

    输出#3

    0

说明/提示

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.

在第一个例子中,你可以移除任意一个值为 22 的元素,使得数组变为 [5,1,2,2][5, 1, 2, 2]。该数组的和为 1010,且存在一个元素等于其余元素之和(5=1+2+25 = 1 + 2 + 2)。

在第二个例子中,你可以移除 88,使得数组变为 [3,5,2][3, 5, 2]。该数组的和为 1010,且存在一个元素等于其余元素之和(5=3+25 = 3 + 2)。你也可以移除 22,使得数组变为 [8,3,5][8, 3, 5]。该数组的和为 1616,且存在一个元素等于其余元素之和(8=3+58 = 3 + 5)。

在第三个例子中,你无法通过恰好移除一个元素使给定数组变为“好数组”。

输入解题思路,AI测评打分。不知道怎么写?

首页