| UDESC Selection Contest 2024-1 |
|---|
| Finished |
Eric has just bought a new game for his NES, called Battletoads. The objective of the game is to defeat the Dark Queen and her army of space mutants.
After spending a long time trying to beat the game, he realized that it was very difficult to kill the Dark Queen because his character had no weapons and needed to defeat her using only punches.
Frustrated by not being able to defeat the game's final boss, Eric decided to develop a new game, which he named Battlefrogs. In this game, the final boss is called Light Queen and the playable characters are always equipped with a laser weapon. The weapon works as follows:
Let $$$E$$$ be the weapon's energy.
Before reaching the Light Queen's level, Eric must pass through $$$N$$$ levels numbered from $$$1$$$ to $$$N$$$, starting from level $$$1$$$. Each level contains $$$s_i$$$ space mutants on the way and an energy bank with power $$$e_i$$$ that charges his weapon by $$$e_i$$$ units. Additionally, at the start of each level, there is an alternative route with a wormhole guarded by $$$X$$$ space mutants that allows Eric to skip $$$k$$$ levels ahead.
If Eric uses the wormhole at level $$$i$$$, he immediately jumps to level $$$i+k$$$, or, if the $$$(i+k)$$$-th level does not exist, to the Light Queen's level. When using the wormhole, Eric does not need to kill any of the $$$s_i$$$ mutants, but he will not be able to charge his weapon by $$$e_i$$$ units and is required to kill the $$$X$$$ mutants guarding the wormhole. If he decides not to use the wormhole at level $$$i$$$, he must defeat the $$$s_i$$$ space mutants, will be able to increase his weapon's energy by $$$e_i$$$ units, and will proceed to level $$$(i + 1)$$$, or to the Light Queen's level if the $$$(i + 1)$$$-th level does not exist.
Knowing that the Light Queen dies when her life reaches $$$0$$$ and that Eric's weapon starts with $$$0$$$ energy, he is now thinking about balancing the game and needs to decide how much life to assign to the final boss. He asked you: what is the maximum amount of life the Light Queen can have so that it is still possible to defeat her?
The first line of the input consists of three integers $$$N$$$ $$$(1 \le N \le 2 \cdot 10^5)$$$, the number of levels in Battlefrogs, $$$k$$$ $$$(1 \le k \le N)$$$, how many levels ahead each wormhole takes Eric, and $$$X$$$ $$$(0 \le X \le 10^9)$$$, the number of space mutants guarding each wormhole.
Then, there are $$$N$$$ lines, where the $$$i$$$-th line contains two integers $$$s_i$$$ and $$$e_i$$$, representing the number of space mutants and the power of the energy bank at level $$$i$$$, respectively.
The output must contain a single integer, the maximum life the Light Queen can have such that it is possible to defeat her.
4 2 11 24 65 23 11
8
5 3 203 42 25 63 18 5
0
If Eric's weapon cannot reach the Light Queen with energy greater than zero, the Light Queen's life must be zero.
| Name |
|---|


