/
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 233 点
問題文
あるクラスには N 人の生徒がおり、生徒には 1 から N までの番号が付けられています。クラス委員長を投票で決めることになりました。
投票の結果、生徒 i は A_i 票を獲得しました。
最も多くの票を獲得した生徒がただ 1 人であれば、その生徒がクラス委員長に選ばれます。
しかし、最多得票の生徒が複数いる場合は、委員長を 1 人に決めることができません。
最多得票の生徒がただ 1 人であるならその生徒の番号を、そうでないなら -1 を出力してください。
制約
- 1 \leq N \leq 2 \times 10^5
- 0 \leq A_i \leq 10^9
- 入力はすべて整数
入力
N A_1 A_2 \dots A_N
- 1 行目には、生徒の人数 N が与えられる。
- 2 行目には、生徒 1 から生徒 N までの得票数 A_1, A_2, \ldots, A_N が空白区切りで与えられる。
出力
最多得票の生徒がただ 1 人であるならその生徒の番号を、そうでないなら -1 を 1 行で出力せよ。
入力例 1
4 3 1 4 2
出力例 1
3
入力例 2
5 7 2 7 1 0
出力例 2
-1
入力例 3
8 12 5 19 7 3 8 21 1
出力例 3
7
入力例 4
20 15 23 8 42 17 9 31 0 26 14 38 7 29 50 13 21 5 44 32 18
出力例 4
14
入力例 5
1 0
出力例 5
1
Score : 233 pts
Problem Statement
A class has N students, numbered from 1 to N. The class representative will be decided by voting.
As a result of the vote, student i received A_i votes.
If there is exactly one student who received the most votes, that student is elected as the class representative. However, if there are multiple students with the highest number of votes, the representative cannot be decided.
If there is exactly one student with the most votes, output that student's number; otherwise, output -1.
Constraints
- 1 \leq N \leq 2 \times 10^5
- 0 \leq A_i \leq 10^9
- All inputs are integers
Input
N A_1 A_2 \dots A_N
- The first line gives the number of students N.
- The second line gives the vote counts A_1, A_2, \ldots, A_N for students 1 through N, separated by spaces.
Output
If there is exactly one student with the most votes, output that student's number; otherwise, output -1 on a single line.
Sample Input 1
4 3 1 4 2
Sample Output 1
3
Sample Input 2
5 7 2 7 1 0
Sample Output 2
-1
Sample Input 3
8 12 5 19 7 3 8 21 1
Sample Output 3
7
Sample Input 4
20 15 23 8 42 17 9 31 0 26 14 38 7 29 50 13 21 5 44 32 18
Sample Output 4
14
Sample Input 5
1 0
Sample Output 5
1