Candy
면접 대비시간 제한3초메모리 제한1024 MB
인접한 원소를 교환해 처음 F개의 합이 T 이상이 되도록 만들 때 필요한 최소 교환 횟수를 구한다.
문제
In the ancient city of Ica, there is said to be a palace with wealth beyond imagination. Inside, there is a corridor with boxes of candy from all over the world. Travellers passing by can take as much candy as they want, provided that they pay its weight in gold.
The boxes of candy are numbered to from left to right. In box , there are units of candy left, where is a non-negative integer.
As the guardian of the palace, you would like to move the boxes around so that boxes with a lot of candy end up closer to the entrance.
You are given the array , as well as the numbers and . In a single operation, you are allowed to swap two adjacent elements of . What is the minimum number of operations required so that the first elements of the array sum to at least ?
입력
The first line of the input contains three integers, , , and .
The second line of the input contains integers .
출력
If it is impossible to achieve the objective using the operations, print NO.
Otherwise, print a single integer, the minimal number of operations.
제한
- .
- .
- .
- for .
The numbers in the input may not fit in a -bit integer, so be aware of overflows if you are using C++.
힌트
In the first sample test case, the first two elements should sum to at least . This can be achieved by a single swap of two adjacent elements: swap the and . After this swap, the array becomes 10 20 4 6 3 3, and indeed the first two elements sum to .
In the second sample test case, the must move all the way to the end of the array; this takes three swaps.
In the third sample test case, it is impossible to make the first two elements sum to at least ; the best we can do is .