#P10177. 似巨龙高歌
似巨龙高歌
Background

Thanks to whk, a top-tier expert, and Fan Ju (bx).
Although Fanfan is very strong in academic subjects, during the New Year he does not want to put too much pressure on other students of the same age, so he plans to tamper with his exam results over the year.
Problem Description
Looking at his grades soaring like a giant dragon, when the New Year arrives, Fanfan cannot help but sing Love You.
This year he has a total of exams, and in the -th exam his rank is .
This creates pressure for other classmates, so he wants to reorder his ranks so that the exam with the largest improvement has the smallest possible improvement in rank, so that he can hide his true strength.
For the -th and the -th exams (), his improvement in rank is . If this value is negative, it means he got worse.
Please help him.
Input Format
There are two lines of input.
The first line contains an integer .
The second line contains integers, separated by spaces. The -th integer is .
Output Format
Output one line containing one integer, which is the answer.
2
1 1
0
4
2 4 1 3
-1
Hint
Sample 1 Explanation
If Fanfan does not change the original exam sequence, then from the first to the second exam he improves by places (the rank does not change).
Sample 2 Explanation
Fanfan can reorder his exam ranks as . Then for every exam he improves by , so the answer is .
This problem uses bundled testdata.
Constraints
-
For of the testdata, is guaranteed.
-
For of the testdata, is guaranteed.
-
For the remaining of the testdata, is guaranteed.
-
For of the testdata, and are guaranteed.
Translated by ChatGPT 5