풀이)
처음 얻은 득표수에 대해, 나머지 득표수들을 하나씩 줄이면서, 처음 얻은 득표수를 하나씩 늘릴 때 나머지 득표수 중 가장 큰 득표수보다 처음의 득표수가 커지면 해결된다.
내 코드)
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Collections;
import java.util.PriorityQueue;
public class Main {
private void solution() throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
int a = Integer.parseInt(br.readLine());
PriorityQueue<Integer> pq = new PriorityQueue<>(Collections.reverseOrder());
while (n-->1) pq.add(Integer.parseInt(br.readLine()));
int cnt = 0;
while (!pq.isEmpty() && pq.peek() >= a) {
cnt++;
a++;
pq.add(pq.poll()-1);
}
System.out.println(cnt);
}
public static void main(String[] args) throws Exception {
new Main().solution();
}
}