-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path국회의원 선거.java
More file actions
44 lines (35 loc) · 1.01 KB
/
국회의원 선거.java
File metadata and controls
44 lines (35 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// 국회의원 선거
import java.util.*;
import java.lang.*;
import java.io.*;
class Main {
public static void main(String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
int[] votes = new int[n];
int cnt = 0;
for (int i = 0; i < n; i++) {
votes[i] = Integer.parseInt(br.readLine());
}
if (n == 1) {
System.out.println(0);
return;
}
while(true) {
int maxIndex = 1;
for (int i = 1; i < n; i++) {
if (votes[i] > votes[maxIndex]) {
maxIndex = i;
}
}
if (votes[0] <= votes[maxIndex]) {
votes[maxIndex]--;
votes[0]++;
cnt++;
} else {
break;
}
}
System.out.println(cnt);
}
}