Railways
InterviewTime limit3sMemory limit128 MB
Process train seat requests in order; accept a request only if every section it covers has enough free seats, and report T or N for each.
- Level
Medium7 of 10
- Topics
- Segment tree, Array, Greedy, Implementation
- Solved
- No attempts yet
Problem
Byteotia State Railways runs a single InterCity line through cities, numbered from to in the order the train visits them (city is the start and city is the end). The train has seats, and between any two consecutive stations it may carry at most passengers.
Seat reservation requests arrive one at a time and must be answered in the order they arrive. A single request asks for seats on the stretch from station to station , so it occupies seats on every section between two consecutive stations from up to , that is, sections .
A request is accepted only when every one of those sections still has at least free seats at the moment it is processed. Partial fulfilment is not allowed: the train cannot serve only part of the route or fewer passengers than asked. When a request is accepted, the number of occupied seats on each affected section grows by ; when it is rejected, nothing changes.
Read the description of the line and the list of requests, decide which requests are accepted and which are rejected, and report the answer for every request.
Input
The first line contains three integers , and (, , ), separated by single spaces: the number of cities on the line, the number of seats in the train, and the number of requests.
Each of the next lines describes one request in arrival order. Line holds the -th request as three integers , and (, ), separated by single spaces: the origin station, the destination station, and the number of seats requested.
Output
Print lines. On line print a single character: T if the -th request is accepted, or N if it is rejected.