Logo
(追記) (追記ここまで)

31056번 - Train Scheduling 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 1024 MB54271448.276%

문제

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

There are $N$ (1ドル\le N\le 5000$) trains whose departure times need to be scheduled. The $i$th train must leave station $s_i$ at time $t_i$ or later ($s_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 $i$ is scheduled to leave at time $a_i\ge t_i,ドル the total delay is defined as $\sum_{i=1}^N(a_i-t_i)$.

입력

The first line contains $N$ and $T$.

Then $N$ lines follow, where the $i$th line contains the station $s_i$ and time $t_i$ corresponding to the $i$th train.

출력

The minimum possible total delay over all valid schedules.

제한

예제 입력 1

1 95
B 63

예제 출력 1

0

The only train leaves on time.

예제 입력 2

4 1
B 3
B 2
A 1
A 3

예제 출력 2

1

There are two optimal schedules. One option is to have trains 2,3,4ドル$ leave on time and train 1ドル$ leave after a one-minute delay. Another is to have trains 1,2,3ドル$ leave on time and train 4ドル$ leave after a one-minute delay.

예제 입력 3

4 10
A 1
B 2
A 3
A 21

예제 출력 3

13

The optimal schedule is to have trains 1ドル$ and 3ドル$ leave on time, train 2ドル$ leave at time 13ドル,ドル and train 4ドル$ leave at time 23ドル$. The total delay is 0ドル+11+0+2=13$.

예제 입력 4

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

예제 출력 4

548047356974

힌트

출처

Olympiad > USA Computing Olympiad > 2023-2024 Season > USACO 2023 December Contest > Platinum 3번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /