#P15436. [蓝桥杯 2025 国 Python B] 魔法护盾
[蓝桥杯 2025 国 Python B] 魔法护盾
Problem Description
In a magic world, a warrior needs to pass through a dangerous maze. The maze has rooms in a line, numbered from to from left to right. The warrior must start from room and go through rooms in order, and only succeeds after leaving room . Each room contains magic shields and magic attacks.
Magic shields can be accumulated, but there is a maximum capacity limit. Room has magic shields (possibly negative, meaning the shield is consumed), and the maximum accumulated shield capacity is .
At the same time, each room may have a magic attack. Let be the attack power of room . If the shields accumulated by the warrior in a room are less than the attack power, the warrior fails to pass.
Key rules:
- Initially, the warrior has shields.
- When entering room , the warrior first gains shields ( means losing shields), and then faces the attack .
- Shields have an upper limit. The accumulated shields cannot exceed . If after gaining shields the number of shields is greater than , it immediately becomes .
- If in any room the number of shields is less than the attack power, the adventure fails.
- You may optionally choose some rooms to apply a “shield amplification” effect. In a chosen room, the effect of is doubled. This effect does not affect .
Compute the minimum number of rooms that need to use shield amplification for the warrior to successfully pass all rooms. If it is impossible to pass the maze no matter what, output the integer .
Input Format
The first line contains three integers , separated by a single space, representing the number of rooms, the maximum shield capacity, and the initial shields.
The second line contains integers , separated by a single space, where represents the shield change in room .
The third line contains integers , separated by a single space, where represents the attack power in room .
Output Format
Output one line containing one integer, the answer, i.e., the minimum number of rooms that need shield amplification to successfully pass the maze. If it is impossible to pass, output the integer .
5 9 2
6 -3 6 -1 -4
9 6 6 7 4
1
9 9 0
5 3 9 5 -3 7 -1 3 -5
3 4 3 4 2 8 5 1 3
0
Hint
Sample Explanation 1
Apply shield amplification to the first room.
Upon reaching room , the current shields are , so the warrior can pass room .
Upon reaching room , the current shields are , so the warrior can pass room .
Upon reaching room , the current shields are , so the warrior can pass room .
Upon reaching room , the current shields are , so the warrior can pass room .
Upon reaching room , the current shields are , so the warrior can pass room . Therefore, the answer is .
Sample Explanation 2
There is no need to use shield amplification, and the warrior can pass all rooms.
Constraints and Notes for Testdata
For of the testdata, .
For of the testdata, .
For of the testdata, .
For of the testdata, .
For of the testdata, .
For all testdata, , , , , .
Translated by ChatGPT 5