#Q180. 「一本通 5.5 例 4」旅行问题
「一本通 5.5 例 4」旅行问题
Description
Original source: POI 2004
John plans to drive a car around a circular highway. There are a total of stations along the highway, each containing a certain amount of gasoline (some stations may have zero fuel). Each liter of gasoline allows the car to travel one kilometer. John must start from one of the stations, travel continuously in either a clockwise or counter-clockwise direction, visit all stations, and return to the starting point. Initially, the car has zero fuel. Upon arriving at each station, John takes all the gasoline available at that station (including the starting station). During the journey, the car must never run out of fuel.
Task: Determine for each station whether John can successfully complete the round trip starting from it.
Input Format
The first line contains an integer , the number of stations on the circular highway.
The next lines each contain two integers and , representing the amount of gasoline stored at the -th station and the distance from the -th station to the next station, respectively.
Output Format
Output lines. For the -th station, if John can successfully complete the round trip starting from it by traveling continuously in either a clockwise or counter-clockwise direction, output TAK on the -th line; otherwise, output NIE.
Sample 1
5
3 1
1 2
5 2
0 1
5 4
TAK
NIE
TAK
NIE
TAK
Data Range and Hints
For all data, , , and .