UberOA #54
Minimum Right Shifts to Sort the Array
估计简单可在线判题
考点(AI 标注)原地数组
The array contains distinct positive integers. Each operation moves the last element to the front and shifts the other elements one position right. Find the minimum number of operations to make the array strictly increasing, or −1 if impossible.
This site has made the standard input and output explicit.
输入格式
The first line contains n, and the second line contains n distinct integers; 1≤n≤100, 1≤a[i]≤100.
输出格式
Output one integer, the answer.
样例 1
输入:
5
3 4 5 1 2
输出:
2
样例 2
输入:
3
1 3 5
输出:
0
样例 3
输入:
3
2 1 4
输出:
-1
样例说明
Example 1: two consecutive right shifts give 1, 2, 3, 4, 5, so the answer is 2. Example 2: already sorted, so the answer is 0. Example 3: the cycle has two descending edges, 2→1 and 4→2, so rotation alone cannot sort it; output −1.