PivotOJ

Gas Station

시간 제한: 1000ms메모리 제한: 1024MB출처: ICPC Rocky Mountain Regional 2023-2024BOJ 30546

문제

You are a late night attendant at a busy gas station. You can only go home after all the cars have topped up their fuel tanks and left the gas station. The gas station you work at has PP gas pump columns, counting from left to right, and each column has two gas pumps, pump A and pump B. A pump can serve cars with left side fuel doors on its right side, or cars with right side fuel doors on its left side. A pump can serve a car on its left side and a car on its right side simultaneously. Thus, each pump column has two lanes for cars.

Cars arriving at the gas station follow strict rules. A car will go to the leftmost open lane that is suitable for its fuel door side. If there are no open lanes, the car will queue up for the suitable lane with the shortest queue. If there are multiple lanes with the shortest queue, the car will queue up in the leftmost one. Once a car has joined a queue, it cannot switch to a different one. After cars leave after refueling and a lane becomes open, the next car in the queue for that lane will go to use a pump.

A lane is open if pump A is available. If pump B is available but pump A is occupied, the lane is not open. When a car goes to an open lane, if both pumps are available, the car will go to pump B, otherwise it will go to pump A. If a car arrives at the same time as some other cars have just finished filling up and left, the new car waits for all other cars in the queues to move to the open pumps (if any) before deciding where to queue. When a car leaves from a pump A, but the pump B ahead of it is occupied, the car is stil able to leave immediately.

You know that Car ii arrives at time tit_i, requires just under fif_i minutes to fill up and leave, and has its fuel door on the sis_i side.

Knowing all this, you want to know when you will be able to go home.

입력

The first line of input contains two space separated integers, 1P101\leq P\leq 10, the number of gas pump columns, and 1N10001\leq N\leq1000, the total number of cars that will arrive.

The next NN lines each contains two integers 1ti1051\leq t_i\leq10^{5}, 1fi1001\leq f_i\leq100, and a single character R or L for sis_i, all separated by a space.

It is guaranteed that ti<ti+1t_i < t_{i+1} for all 1i<N1 \leq i < N.

출력

Output NN lines containing the time when each car leaves the gas station, in the order that the cars are listed in the input.

예제

예제 1

입력
1 4
1 9 L
2 5 L
3 10 L
4 10 L
출력
10
7
17
27

예제 2

입력
1 4
1 9 L
2 9 L
3 10 L
4 10 L
출력
10
11
21
21

예제 3

입력
1 2
8 11 R
9 10 L
출력
19
19

예제 4

입력
2 10
1 10 R
2 3 R
3 10 R
4 12 R
5 1 R
6 5 R
7 10 R
10 2 R
11 7 R
13 4 R
출력
11
5
13
16
6
11
21
18
18
22
코드를 제출하려면 로그인하세요.