Candy

Time limit: 1.5s
Memory limit: 128MB
Input:
Output:

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 of candy are numbered 00 to N1N − 1 from left to right. In box ii, there are aia_i units of candy left, where aia_i 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 a0,a1,,aN1a_0, a_1, …, a_{N - 1}, as well as the numbers FF and TT. In a single operation, you are allowed to swap two adjacent elements of a0,a1,,aN1a_0, a_1, …, a_{N - 1}. What is the minimum number of operations required so that the first FF elements of the array sum to at least TT?

Input

The first line of the input contains three integers, N,FN, F, and TT.

The second line of the input contains N integers a0,a1,,aN1a_0, a_1, …, a_{N - 1}.

Output

If it is impossible to achieve the objective using the operations, print NO.

Otherwise, print a single integer, the minimum number of operations.

Constraints and Scoring

  • 1N1001 \leq N \leq 100
  • 1FN1 \leq F \leq N
  • 0T10110 \leq T \leq 10^{11}
  • 0ai1090 \leq a_i \leq 10^9 for i=0,1,...,N1i = 0, 1, ..., N - 1.

Note: The numbers in the input may not fit in a 3232-bit integer, so be aware of overflows if you are using C++.

Your solution will be tested on a set of test groups, each worth a number of points. Each test group contains a set of test cases. To get the points for a test group, you need to solve all test cases in the test group.

# Score Limits
1 6 N2N ≤ 2 and ai100a_i ≤ 100 for i=0,1,,N1i = 0, 1,…, N − 1 și T109T ≤ 10^9
2 19 ai1a_i ≤ 1 for i=0,1,,N1i = 0, 1, …, N − 1
3 16 N20N \leq 20
4 30 ai100a_i ≤ 100 for i=0,1,,N1i = 0, 1, …, N − 1
5 29 No additional constraints.

Example 1

stdin

6 2 27
10 4 20 6 3 3

stdout

1

Explication

In the first sample test case, the first two elements should sum to at least 2727. This can be achieved by a single swap of two adjacent elements: swap the 44 and 2020. After this swap, the array becomes 10 20 4 6 3 3, and indeed the first two elements sum to 10+20=302710 + 20 = 30 ≥ 27.

Example 2

stdin

6 5 5000000000
1000000000 1000000000 0 1000000000 1000000000 1000000000

stdout

3

Explication

In the second sample test case, the 0 must move all the way to the end of the array; this takes three swaps.

Example 3

stdin

3 2 100
20 30 60

stdout

NO

Explication

In the third sample test case, it is impossible to make the first two elements sum to at least 100100; the best we can do is 60+30=9060 + 30 = 90.

Example 4

stdin

1 1 100
100

stdout

0

Problem info

ID: 984

Editors:

Author:

Source: EGOI 2023: Day 2, Problem 2

Tags:

EGOI 2023 Day 2

Log in or sign up to be able to send submissions!