#P9468. [EGOI 2023] Candy / 糖果
[EGOI 2023] Candy / 糖果
Background
Day 2 Problem B.
Translated from EGOI2023 candy.
Problem Description
In the city of Ikaagu, it is said that there is a palace whose wealth is beyond imagination. Inside it, along a corridor, there are boxes of candy from all over the world. Any traveler passing by can take as much candy as they want, as long as they pay gold equal to the weight of the candy.
The boxes are numbered from left to right from to . In box , there are units of candy remaining, where is a non-negative integer.
As the guardian of the palace, you need to move these boxes so that boxes with lots of candy are closer to the entrance.
You are given the array , and integers and . In one operation, you are allowed to swap any two adjacent elements in . What is the minimum number of operations needed to make the sum of the first elements of the array at least ?
Input Format
The first line contains three integers .
The second line contains integers .
Output Format
If it is impossible to achieve the goal, output NO.
Otherwise, output one integer, the minimum number of operations.
6 2 27
10 4 20 6 3 3
1
6 5 5000000000
1000000000 1000000000 0 1000000000 1000000000 1000000000
3
3 2 100
20 30 60
NO
1 1 100
100
0
Hint
Sample Explanation
In sample , the sum of the first two elements must be at least . This can be achieved with one adjacent swap: swap and . After the swap, the array becomes 10 20 4 6 3 3, and the sum of the first two elements is .
Sample Explanation
In sample , the must be moved all the way to the end of the array; this requires swaps.
Sample Explanation
In sample , it is impossible to make the sum of the first two elements at least ; the best we can do is .
Constraints
For all testdata, , , , .
- Subtask 1 ( points): , , .
- Subtask 2 ( points): .
- Subtask 3 ( points): .
- Subtask 4 ( points): .
- Subtask 5 ( points): no additional constraints.
Hint
The answer may not fit in a 32-bit integer. If you use C++, watch out for possible overflow.
Translated by ChatGPT 5
