Polish version    English version  
  About Olympic -> Problems


 News
 About Olympic
About contest
Problems
I OI 1993/1994
II OI 1994/1995
III OI 1995/1996
IV OI 1996/1997
V OI 1997/1998
VI OI 1998/1999
VII OI 1999/2000
VIII OI 2000/2001
IX OI 2001/2002
X OI 2002/2003
XI OI 2003/2004
XII OI 2004/2005
XIII OI 2005/2006
XIV OI 2006/2007
XV OI 2007/2008
Problems archive
 History of OI
 OI books
 National team
 Olympic camps
 Photo gallery
 Links
 SIO
 MAIN
IX Olimpiada Informatyczna 2001/2002

Task: kol
Author: Tomasz Waleń
Railways

I stage contest  

Byteotian State Railways decided to keep up with the times and introduce to their offer an InterCity connection. Because of lack of efficient engines, clean carriages and straight tracks it was possible to establish only one such a connection. The lack of any computer system for seat reservation was another obstacle. Writing the main part of this system is your task.

For simplicity we assume that the InterCity connection runs through c cities numbered successively from 1 to c (the starting city has the number 1, and c is the number of the ending city). There are s seats in the train and transporting more passengers between any two successive stations is not allowed.

The computer system is to receive successive requests and determine whether they may be fulfilled. A request is accepted when in the given section of the railway line there is enough vacant seats in the train. Otherwise it is rejected. Partial accepting of a request is not allowed, e.g. for a part of a route or for less passengers. After accepting a request, the number of vacant seats in the train is updated. The requests are processed successively in the order of coming.

Task

Write a program which:
  • reads from the text file kol.in the description of the connection and a list of requested reservations,
  • computes which requests will be accepted, and which will be rejected,
  • writes to the text file kol.out the answers to all the requests.

Input

In the first line of the text file kol.in there are three integers c, s and r (1<=c<=60 000, 1<=s<=60 000, 1<=r<=60 000) separated by single spaces. The numbers denote respectively: the number of cities on the railway line, the number of seats in the train, and the number of requests. In the following r lines there are consecutive requests written. In the line of number i+1 there is the i-th request described. The description consists of three integers o, d and n (1<=o<d<=c, 1<=n<=s) separated by single spaces. They denote: the number of the station of origin, the number of the destination station and the requested number of seats, respectively.

Output

Your program should write r lines to the text file kol.out. In the i-th line there should be exactly one character:
  • T (for "yes") - if the i-th request is accepted,
  • N (for "no") - otherwise.

Example

For the following input file kol.in:
4 6 4
1 4 2
1 3 2
2 4 3
1 2 3
the correct answer is in the following output file kol.out:
T
T
N
N



Print friendly version