#P3422. [POI 2005] LOT-A Journey to Mars
[POI 2005] LOT-A Journey to Mars
Description
All space stations on Mars lie on a circle. Byteazar lands at one of the stations and then starts traveling around the circle.
Travel consumes fuel: liter of fuel allows traveling meter. Each station provides a different amount of fuel.
At each station, Byteazar may take all the fuel available there (his fuel tank has no capacity limit). However, if at any moment he runs out of fuel while moving, the trip fails.
Byteazar needs to decide at which station to land so that he can successfully visit all stations and return to his starting station. After landing, he may choose either direction to travel.
Input Format
The first line contains an integer , the number of stations. The stations are numbered from to .
Then follow lines. Each of the next lines contains two integers . The -th line describes station , where is the amount of fuel available at station , and is the distance from station to station . For station , is the distance from station to station .
Output Format
Output lines, each containing the string TAK or NIE.
If landing at station is feasible, print TAK on line ; otherwise, print NIE.
5
3 1
1 2
5 2
0 1
5 4
TAK
NIE
TAK
NIE
TAK
Hint
Constraints
For of the testdata, , , , and .
Translated by ChatGPT 5
京公网安备 11011102002149号