QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 32 MB Total points: 100

#13521. Railways

Statistics

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 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 standard input 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 standard output the answers to all the requests.

Input

In the first line of the standard input there are three integers $c$, $s$ and $r$ ($1 \le c \le 60\,000$, $1 \le s \le 60\,000$, $1 \le r \le 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 \le o < d \le c$, $1 \le n \le 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 standard output. 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

Input

4 6 4
1 4 2
1 3 2
2 4 3
1 2 3

Output

T
T
N
N

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.