Ice Skates
Time limit1sMemory limit128 MB
After each of m membership events, decide whether every current member can be assigned skates, given k pairs of each size and foot sizes with tolerance d.
- Level
Hard8 of 10
- Topics
- Segment tree, Greedy, Prefix sum
- Solved
- No attempts yet
Problem
Byteasar runs a skating club. Its members meet regularly to train together, and they always use the club's ice skates. Skate sizes are numbered from to .
Each member has a foot size, but that alone does not determine which skates they can wear: a skater has a size tolerance , so a skater whose foot size is can wear any skate of size from to . A skater always wears a single pair of skates of the same size, never two different sizes at once.
To stock the club, Byteasar bought pairs of skates of every size, that is pairs for each size from to . Over time some people join the club while others leave, and Byteasar worries whether he will always have enough skates of a suitable size for every current member.
At the start the club has no members. You are given a sequence of events. Each event means that members with foot size have just joined the club (when ) or just left it (when ). Immediately after every event, decide whether Byteasar has skates of a suitable size for every member of the club at that moment.
Input
The first line contains four integers , , , and (, , , ), separated by single spaces: the largest skate size, the number of events, the number of skate pairs bought of each size, and the size tolerance.
Each of the next lines describes one event with two integers and (, ), separated by a single space. If , then new members with foot size have just joined the club; if , then members with foot size have just left it. The sequence is always consistent: a member who never joined can never leave.
Output
Print lines. The -th line must contain TAK (Polish for yes) if, right after the -th event, Byteasar has skates of a suitable size for every club member, or NIE (Polish for no) otherwise.
Note
To see how a full assignment can work, suppose that at some moment three members can wear skates of size or , two members can wear size or , and three members can wear size or . Two pairs of skates of each of the sizes , , , and are then enough for everyone:
- two members take skates of size ;
- the size- skates go to one member who can wear size or and one who can wear size or ;
- the size- skates go to one member who can wear size or and one who can wear size or ;
- the remaining two members take skates of size .