#640
Unrated
Train Scheduling
시간 제한
2s
메모리 제한
1024MB
제출
0
정답
0
맞힌 사람
0
정답 비율
0.0%

문제

Note: The memory limit for this problem is 512MB, twice the default.

Bessie has taken on a new job as a train dispatcher! There are two train stations: AA and BB. Due to budget constraints, there is only a single track connecting the stations. If a train departs a station at time tt, then it will arrive at the other station at time t+Tt+T (1T10121\le T\le 10^{12}).

There are NN (1N50001\le N\le 5000) trains whose departure times need to be scheduled. The iith train must leave station sis_i at time tit_i or later (si{A,B},0ti1012s_i\in \{A, B\}, 0\le t_i\le 10^{12}). It is not permitted to have trains going in opposite directions along the track at the same time (since they would crash). However, it is permitted to have many trains on the track going in the same direction at the same time (assume trains have negligible size).

Help Bessie schedule the departure times of all trains such that there are no crashes and the total delay is minimized. If train ii is scheduled to leave at time aitia_i\ge t_i, the total delay is defined as i=1N(aiti)\sum_{i=1}^N(a_i-t_i).

입력

The first line contains NN and TT.

Then NN lines follow, where the iith line contains the station sis_i and time tit_i corresponding to the iith train.

출력

The minimum possible total delay over all valid schedules.

예제 입력 1

1 95
B 63

예제 출력 1

0

예제 입력 2

4 1
B 3
B 2
A 1
A 3

예제 출력 2

1

예제 입력 3

4 10
A 1
B 2
A 3
A 21

예제 출력 3

13

예제 입력 4

8 125000000000
B 17108575619
B 57117098303
A 42515717584
B 26473500855
A 108514697534
B 110763448122
B 117731666682
A 29117227954

예제 출력 4

548047356974

점수

Inputs 5-6: N15N \le 15Inputs 7-10: N100N \le 100Inputs 11-14: N500N \le 500Inputs 15-18: N2000N\le 2000Inputs 19-24: No additional constraints

코드 제출

코드를 제출하려면 로그인이 필요합니다.

로그인
내 제출
제출 내역이 없습니다.
맞은 사람
아직 맞은 사람이 없습니다.
난이도 투표
Unrated0명 투표
로그인 후 AC 받으면 투표할 수 있습니다.
전체 제출
제출 내역이 없습니다.