#P4025. [PA 2014] Bohater
[PA 2014] Bohater
Description
In a computer game, you need to defeat monsters (numbered from to ).
To defeat monster , you need to spend health points, but after the monster dies, it drops a healing potion that restores health points.
At any time, your health must not drop to (or below).
Determine whether there exists an order of fighting such that you can defeat all monsters without dying.
Input Format
The first line contains two integers , representing the number of monsters and your initial health.
The next lines each contain two integers .
Output Format
The first line is TAK (yes) or NIE (no), indicating whether such an order exists.
If the first line is TAK, then the second line contains a permutation of separated by spaces, representing a valid order.
If there are multiple answers, you may output any one of them. (This problem uses SPJ.)
3 5
3 1
4 8
8 3
TAK
2 3 1
Hint
For of the testdata, , .
Translated by ChatGPT 5
京公网安备 11011102002149号