| UFBA Selection Contest 2026 |
|---|
| Закончено |
Welcome to GruPro's Golden Challenge! You are a competitive programmer beginning your journey through UFBA's training curriculum. Your programming journey starts with an initial score of $$$X$$$, and ahead of you lies a series of $$$N$$$ training challenges, each designed to test and refine your programming abilities in different areas.
However, you have the freedom to choose the order in which you tackle challenges. Each challenge $$$i$$$ has two attributes:
When you complete challenge $$$i$$$, your score evolves according to:
$$$$$$ X \leftarrow \min(P_i, X + Q_i) $$$$$$
In other words, your score is adjusted by $$$Q_i$$$ points (which can be a gain or a penalty), but your total score cannot exceed the limit $$$P_i$$$ for that challenge. Some challenges reward you generously while others penalize careless approaches.
Your mission is to complete all $$$N$$$ challenges in the optimal order to maximize your final score. Choose wisely, and you might just achieve the ultimate victory!
The first line contains two integers $$$N$$$ and $$$X$$$ ($$$1 \leq N \leq 10^{5}$$$, $$$1 \leq X \leq 10^{9}$$$).
The next $$$N$$$ lines contain two integers $$$P_i$$$ and $$$Q_i$$$ ($$$-10^{9} \leq P_i, Q_i \leq 10^{9}$$$).
Print a single integer: the maximum final score achievable after completing all challenges in the optimal order.
2 510 38 2
10
3 1015 512 -320 4
16
4 812 210 -415 511 1
12
| Название |
|---|


