Good Bye 2018
E
New Year and the Acquaintance Estimation
Codeforces
2400
原题
← DF →
翻译中…

Bob is an active user of the social network Faithbug. On this network, people are able to engage in a mutual friendship. That is, if $a$ is a friend of $b$, then $b$ is also a friend of $a$. Each user thus has a non-negative amount of friends.

翻译中…

This morning, somebody anonymously sent Bob the following link: graph realization problem and Bob wants to know who that was. In order to do that, he first needs to know how the social network looks like. He investigated the profile of every other person on the network and noted down the number of his friends. However, he neglected to note down the number of his friends. Help him find out how many friends he has. Since there may be many possible answers, print all of them.

翻译中…

Input

翻译中…

The first line contains one integer $n$ ($1 \leq n \leq 5 \cdot 10^5$), the number of people on the network excluding Bob.

翻译中…

The second line contains $n$ numbers $a_1,a_2, \dots, a_n$ ($0 \leq a_i \leq n$), with $a_i$ being the number of people that person $i$ is a friend of.

翻译中…

Output

翻译中…

Print all possible values of $a_{n+1}$ — the amount of people that Bob can be friend of, in increasing order.

翻译中…

If no solution exists, output $-1$.

翻译中…

Note

翻译中…

In the first test case, the only solution is that everyone is friends with everyone. That is why Bob should have $3$ friends.

翻译中…

In the second test case, there are three possible solutions (apart from symmetries):

翻译中…
  • $a$ is friend of $b$, $c$ is friend of $d$, and Bob has no friends, or
  • $a$ is a friend of $b$ and both $c$ and $d$ are friends with Bob, or
  • Bob is friends of everyone.
翻译中…

The third case is impossible to solve, as the second person needs to be a friend with everybody, but the first one is a complete stranger.

翻译中…

样例

Input #1
3
3 3 3
Output #1
3
InputCopy OutputCopy
Input #2
4
1 1 1 1
Output #2
0 2 4
InputCopy OutputCopy
Input #3
2
0 2
Output #3
-1
InputCopy OutputCopy
Input #4
35
21 26 18 4 28 2 15 13 16 25 6 32 11 5 31 17 9 3 24 33 14 27 29 1 20 4 12 7 10 30 34 8 19 23 22
Output #4
13 15 17 19 21
InputCopy OutputCopy
题目信息
题号
1091E
所属比赛
时间限制
2 s
内存限制
256 MB
标签
二分
数据结构
图论
贪心
模拟
数学
排序

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。