#P6715. [CCO 2018] Fun Palace
[CCO 2018] Fun Palace
Description
There is a chain with nodes, and each node has a weight.
For every , there is an edge connecting .
You may place some creatures on any nodes of the chain.
For the -th edge, if node has at least creatures or node has at least creatures, then this edge can be opened.
The chain has an exit. If there are creatures at node , then the exit will be opened.
You need to determine the maximum number of creatures you can place, such that the creatures will not open the exit.
Opening does not necessarily mean they can pass through.
Input Format
The first line contains an integer .
The second line contains an integer .
The next lines each contain two numbers .
Output Format
Output a single number, the maximum number of creatures that can be placed such that the creatures will not escape through the exit.
2
20
5 5
19
2
20
5 20
24
7
7
2 8
6 6
1 1
2 4
2 8
7 8
23
Hint
Sample Explanation
Sample 1 Explanation
If there are more than creatures, the exit will be opened.
Sample 2 Explanation
Suppose we place creatures at node . Then creatures will go to node , but the exit still cannot be opened.
Sample 3 Explanation
Place creatures at node , and place creatures at node .
Constraints
| Subtask ID | Points | Special Constraints |
|---|---|---|
| 1 | , | |
| 2 | ||
| 3 | ||
| 4 | None |
For of the testdata, it is guaranteed that , .
Notes
This problem is translated from Canadian Computing Olympiad 2018 Day 1 T3 Fun Palace.
Translated by ChatGPT 5
京公网安备 11011102002149号