Under construction

Still being built. Things may change

Candy

Interview

Time limit3sMemory limit1024 MB

Summary
Find the fewest adjacent swaps needed to make the first F boxes hold at least T candy in total, or report NO if that is impossible.
Level

Medium6 of 10

Topics
Dynamic programming, Array
Solved
No attempts yet

Problem

In the ancient city of Ica, there is said to be a palace with wealth beyond imagination. Inside, there is a corridor with NN 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 are numbered 00 to N−1N-1 from left to right. Box ii holds aia_i units of candy, where aia_i is a non-negative integer.

As the guardian of the palace, you want to move the boxes so that boxes with a lot of candy end up closer to the entrance.

You are given the array a0,a1,…,aN−1a_0, a_1, \ldots, a_{N-1}, along with the numbers FF and TT. In one operation, you may swap two adjacent elements of the array. What is the minimum number of operations needed so that the first FF elements sum to at least TT?

Input

The first line contains three integers NN, FF, and TT.

The second line contains NN integers a0,a1,…,aN−1a_0, a_1, \ldots, a_{N-1}.

Output

If it is impossible to reach the goal using the operations, print NO. Otherwise, print a single integer, the minimum number of operations.

Constraints

  • 1≤N≤1001 \le N \le 100.
  • 1≤F≤N1 \le F \le N.
  • 0≤T≤10110 \le T \le 10^{11}.
  • 0≤ai≤1090 \le a_i \le 10^9 for i=0,1,…,N−1i = 0, 1, \ldots, N-1.

The input numbers may not fit in a 32-bit integer, so watch for overflow.

Hint

In the first sample, the first two elements should sum to at least 2727. A single swap of the 44 and the 2020 achieves this: the array becomes 10 20 4 6 3 3, and the first two elements sum to 10+20=30≥2710+20=30\ge 27.

In the second sample, the 00 must move all the way to the end of the array, which takes three swaps.

In the third sample, the first two elements cannot reach 100100. The best possible is 60+30=9060+30=90.

Examples4

  1. Example 1

    Input
    6 2 27
    10 4 20 6 3 3
    
    Expected output
    1
    
  2. Example 2

    Input
    6 5 5000000000
    1000000000 1000000000 0 1000000000 1000000000 1000000000
    
    Expected output
    3
    
  3. Example 3

    Input
    3 2 100
    20 30 60
    
    Expected output
    NO
    
  4. Example 4

    Input
    1 1 100
    100
    
    Expected output
    0