A12219 | Good Array
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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]$ is good because there is the element $a_4=7$ which equals to the sum $1 + 3 + 3$ .
You are given an array $a$ consisting of $n$ integers. Your task is to print all indices $j$ of this array such that after removing the $j$ -th element from the array it will be good (let's call such indices nice).
For example, if $a=[8, 3, 5, 2]$ , the nice indices are $1$ and $4$ :
- if you remove $a_1$ , the array will look like $[3, 5, 2]$ and it is good;
- if you remove $a_4$ , the array will look like $[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.
You are given an array $a$ consisting of $n$ integers. Your task is to print all indices $j$ of this array such that after removing the $j$ -th element from the array it will be good (let's call such indices nice).
For example, if $a=[8, 3, 5, 2]$ , the nice indices are $1$ and $4$ :
- if you remove $a_1$ , the array will look like $[3, 5, 2]$ and it is good;
- if you remove $a_4$ , the array will look like $[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.
输入格式
The first line of the input contains one integer $n$ ( $2 \le n \le 2 \cdot 10^5$ ) — the number of elements in the array $a$ .
The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ( $1 \le a_i \le 10^6$ ) — elements of the array $a$ .
The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ( $1 \le a_i \le 10^6$ ) — elements of the array $a$ .
输出格式
In the first line print one integer $k$ — the number of indices $j$ of the array $a$ such that after removing the $j$ -th element from the array it will be good (i.e. print the number of the nice indices).
In the second line print $k$ distinct integers $j_1, j_2, \dots, j_k$ in any order — nice indices of the array $a$ .
If there are no such indices in the array $a$ , just print $0$ in the first line and leave the second line empty or do not print it at all.
In the second line print $k$ distinct integers $j_1, j_2, \dots, j_k$ in any order — nice indices of the array $a$ .
If there are no such indices in the array $a$ , just print $0$ in the first line and leave the second line empty or do not print it at all.
输入输出样例
输入 #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 $2$ so the array will look like $[5, 1, 2, 2]$ . The sum of this array is $10$ and there is an element equals to the sum of remaining elements ( $5 = 1 + 2 + 2$ ).
In the second example you can remove $8$ so the array will look like $[3, 5, 2]$ . The sum of this array is $10$ and there is an element equals to the sum of remaining elements ( $5 = 3 + 2$ ). You can also remove $2$ so the array will look like $[8, 3, 5]$ . The sum of this array is $16$ and there is an element equals to the sum of remaining elements ( $8 = 3 + 5$ ).
In the third example you cannot make the given array good by removing exactly one element.
In the second example you can remove $8$ so the array will look like $[3, 5, 2]$ . The sum of this array is $10$ and there is an element equals to the sum of remaining elements ( $5 = 3 + 2$ ). You can also remove $2$ so the array will look like $[8, 3, 5]$ . The sum of this array is $16$ and there is an element equals to the sum of remaining elements ( $8 = 3 + 5$ ).
In the third example you cannot make the given array good by removing exactly one element.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted