#P15436. [蓝桥杯 2025 国 Python B] 魔法护盾

    ID: 17456 远端评测题 2000ms 512MiB 尝试: 0 已通过: 0 显示难度普及 上传者: 标签>动态规划 DP2025背包 DP蓝桥杯国赛

[蓝桥杯 2025 国 Python B] 魔法护盾

Problem Description

In a magic world, a warrior needs to pass through a dangerous maze. The maze has nn rooms in a line, numbered from 11 to nn from left to right. The warrior must start from room 11 and go through rooms in order, and only succeeds after leaving room nn. Each room contains magic shields and magic attacks.

Magic shields can be accumulated, but there is a maximum capacity limit. Room ii has sis_i magic shields (possibly negative, meaning the shield is consumed), and the maximum accumulated shield capacity is cc.

At the same time, each room may have a magic attack. Let aia_i be the attack power of room ii. 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 bb shields.
  • When entering room ii, the warrior first gains sis_i shields (si<0s_i < 0 means losing si|s_i| shields), and then faces the attack aia_i.
  • Shields have an upper limit. The accumulated shields cannot exceed cc. If after gaining shields the number of shields is greater than cc, it immediately becomes cc.
  • 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 sis_i is doubled. This effect does not affect aia_i.

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 1-1.

Input Format

The first line contains three integers n,c,bn, c, b, separated by a single space, representing the number of rooms, the maximum shield capacity, and the initial shields.

The second line contains nn integers s1,s2,,sns_1, s_2, \dots, s_n, separated by a single space, where sis_i represents the shield change in room ii.

The third line contains nn integers a1,a2,,ana_1, a_2, \dots, a_n, separated by a single space, where aia_i represents the attack power in room ii.

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 1-1.

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 11, the current shields are min(2+6×2,9)=99\min(2 + 6 \times 2, 9) = 9 \ge 9, so the warrior can pass room 11.

Upon reaching room 22, the current shields are 93=669 - 3 = 6 \ge 6, so the warrior can pass room 22.

Upon reaching room 33, the current shields are min(6+6,9)=96\min(6 + 6, 9) = 9 \ge 6, so the warrior can pass room 33.

Upon reaching room 44, the current shields are 91=879 - 1 = 8 \ge 7, so the warrior can pass room 44.

Upon reaching room 55, the current shields are 84=448 - 4 = 4 \ge 4, so the warrior can pass room 55. Therefore, the answer is 11.

Sample Explanation 2

There is no need to use shield amplification, and the warrior can pass all rooms.

Constraints and Notes for Testdata

For 25%25\% of the testdata, 1n101 \le n \le 10.

For 50%50\% of the testdata, 1n201 \le n \le 20.

For 60%60\% of the testdata, 1n501 \le n \le 50.

For 70%70\% of the testdata, 1n1001 \le n \le 100.

For 80%80\% of the testdata, 1n10001 \le n \le 1000.

For all testdata, 1n100001 \le n \le 10000, 10000si10000-10000 \le s_i \le 10000, 1ai100001 \le a_i \le 10000, 1c500001 \le c \le 50000, 0b500000 \le b \le 50000.

Translated by ChatGPT 5