P17495 [ICPC 2026 Wuhan I] Believe in You
Description
*Slay the Spire 2* is a world-renowned game. In this game, you play as a character climbing a high tower, using cards to defeat monsters along the way until victory is achieved.
Now you must face a powerful enemy. Unfortunately, your remaining health cannot withstand even a single unblocked attack. Fortunately, you know the cards you will draw and the monster's actions for the next $n$ turns. You want to quickly determine whether you can defeat the monster within $n$ turns without dying.
The cards in the game are divided into two types:
- Strike: Playing this card deals $S$ points of damage.
- Defend: Playing this card provides $D$ points of block.
The condition to defeat the enemy is that the total damage you deal is greater than or equal to the monster's health $HP$.
In the $i$-th turn, the player's actions are defined as:
- Discard the cards currently in hand and clear any remaining block from the previous turn (if any).
- Draw $a_i$ Strike cards and $5-a_i$ Defend cards.
- Choose and play no more than $3$ cards; each card can only be played once.
- End the action.
In the $i$-th turn, the monster's action is defined as:
- Deal $k_i$ points of damage to the player. If $k_i$ is greater than the player's current block value, you will die, and the game ends immediately.
- End the action.
In each turn, the order of actions for both parties is:
1. Player's turn.
2. If the monster dies, the player wins, and the game ends.
3. Monster's turn.
4. If the player dies, the game ends.
You need to determine if you can defeat the monster within $n$ turns. If you can, output “Yes” and the earliest turn in which the monster can be defeated; if you cannot defeat the monster within $n$ turns or if the player dies during the process, output “No”.
Input Format
The first line contains an integer $n$ ($1 \le n \le 100$), representing the predicted number of game turns.
The second line contains three positive integers $S,D,HP$ ($1 \le S,D \le 10$, $1 \le HP \le 100$), representing the damage dealt by a Strike, the block provided by a Defend, and the monster's health, respectively.
The next $n$ lines each contain two non-negative integers $a_i,k_i$ ($0 \le a_i \le 5$, $0 \le k_i \le 50$), describing the card draw situation for the $i$-th turn (drawing $a_i$ Strikes) and the monster's attack damage.
Output Format
If the monster can be defeated within $n$ turns, output “Yes” on one line, and output an integer on the next line representing the earliest turn in which the monster is defeated.
If the monster cannot be defeated within $n$ turns or if the player dies, output “No”.
Explanation/Hint
For the 1st sample case, the optimal card-playing strategy is as follows:
- Turn 1: The player draws $4$ Strikes and $1$ Defend. The monster's attack power is $0$. The player plays $3$ Strikes, dealing $15$ points of damage. At the end of the turn, the monster has $15$ health remaining. The player receives $0$ damage and survives.
- Turn 2: The player draws $1$ Strike and $4$ Defends. The monster's attack power is $10$. To survive, the player must play $2$ Defends to gain $10$ block, leaving $1$ remaining card-play action to play $1$ Strike, dealing $5$ points of damage. At the end of the turn, the monster has $10$ health remaining. The player receives a $10$-point attack, which is negated by the block, and survives.
- Turn 3: The player draws $2$ Strikes and $3$ Defends. Since the monster will not perform its attack phase if it dies, the player can directly play $2$ Strikes, dealing $10$ points of damage. At this point, the cumulative damage reaches $30$, the monster dies, and the game ends in the 3rd turn.