Hero
Time limit1sMemory limit256 MB
Order n monsters so a hero with health z survives each d_i hit and collects each a_i reward, printing TAK with the order or NIE.
Problem
Bitor must defeat n monsters in some order with starting health z. Monster i deals d_i damage and then restores a_i health if defeated. Health must stay positive throughout. Decide if all monsters can be defeated and output one winning order.
Input
The first line has n and z. The next n lines give d_i and a_i.
Output
Print NIE if impossible. Otherwise print TAK on the first line and a permutation on the second line.