#P2777. [AHOI2016初中组] 自行车比赛

[AHOI2016初中组] 自行车比赛

Description

Xiaoxue is very interested in bicycle races, especially the Tour of Binhu Lake. The annual Tour of Binhu Lake requires riders to compete for several consecutive days, and the champion is decided by total accumulated points. This year there are NN contestants. Each day’s race produces a ranking: the first-place finisher earns NN points, the second-place finisher earns N1N-1 points, the third-place finisher earns N2N-2 points, and so on, with the last-place finisher earning 11 point. It is guaranteed that no two contestants share the same rank on a given day.

Over the previous days, the NN contestants have already accumulated some points. The final day is about to begin. Xiaoxue wants to know how many contestants still have a chance to become the overall champion — that is, how many contestants can possibly finish with the highest total after the last day’s race.

Input Format

The first line contains an integer NN, the total number of contestants, with 3N3×1053\le N\le 3\times 10^5.

Then follow NN lines. The ii-th line contains an integer BiB_i, the accumulated points already earned by contestant ii, with 0Bi2×1060\le B_i\le 2\times 10^6.

Output Format

Output a single line containing one integer: the number of contestants who can still become the final champion.

3
8
10
9
3
5
15
14
15
12
14
4

Hint

Constraints and Conventions

  • For 20%20\% of the testdata, 3N6003\le N\le 600.
  • For 50%50\% of the testdata, 3N1×1043\le N\le 1\times 10^4.
  • For 100%100\% of the testdata, 3N3×1053\le N\le 3\times 10^5 and 0Bi2×1060\le B_i\le 2\times 10^6.

Translated by ChatGPT 5