#arc138a. [arc138_a]Larger Score
[arc138_a]Larger Score
Problem Statement
We have an integer sequence of length : . Below in this problem, let the score of be the sum of the first terms of . Additionally, let be the score of the sequence given in input.
You can do the following operation any number of times.
- Choose two adjacent elements of and swap them.
Your objective is to make the score at least . Determine whether the objective is achievable. If it is, find the minimum number of operations needed to achieve it.
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
If the objective is not achievable, print -1
. If it is achievable, print the minimum number of operations needed to achieve it.
Sample Input 1
4 2
2 1 1 2
Sample Output 1
2
We have . The following sequence of operations makes the score at least .
- swap and swap and
The objective is not achievable in one operation, so the minimum number of operations needed is .
Sample Input 2
3 1
3 2 1
Sample Output 2
-1
Sample Input 3
20 13
90699850 344821203 373822335 437633059 534203117 523743511 568996900 694866636 683864672 836230375 751240939 942020833 865334948 142779837 22252499 197049878 303376519 366683358 545670804 580980054
Sample Output 3
13