#P9985. [USACO23DEC] Train Scheduling P
[USACO23DEC] Train Scheduling P
Background
Note: The memory limit for this problem is 512MB, twice the default.
Problem Description
Bessie has found a new job in train scheduling. There are now two train stations, and . Due to budget limits, there is only a single-track railway connecting station and station . If a train leaves one of the stations at time , it will arrive at the other station at time ().
Now there are () trains whose departure times need to be scheduled. Train must depart from station after time (, ). Trains traveling in opposite directions are not allowed to be on the track at the same time, or they will collide. However, assume trains have negligible size, so at the same time the track can contain many trains traveling in the same direction.
Help Bessie schedule the departure time for each train, minimizing the total delay while avoiding collisions. Suppose train is scheduled to depart at time . The total delay is .
Input Format
The first line contains and .
The next lines each describe one train. Line contains for train .
Output Format
Output the minimum total delay among all valid schedules.
1 95
B 63
0
4 1
B 3
B 2
A 1
A 3
1
4 10
A 1
B 2
A 3
A 21
13
8 125000000000
B 17108575619
B 57117098303
A 42515717584
B 26473500855
A 108514697534
B 110763448122
B 117731666682
A 29117227954
548047356974
Hint
Sample Explanation 1
The only train departs on time.
Sample Explanation 2
There are two optimal schedules. In the first, trains depart on time, and train departs with a -minute delay. In the second, trains depart on time, and train departs with a -minute delay.
Sample Explanation 3
The optimal schedule is: trains depart on time, train departs at time , and train departs at time . The total delay is .
Test Point Properties
- Test points satisfy .
- Test points satisfy .
- Test points satisfy .
- Test points satisfy .
- Test points have no additional constraints.
Translated by ChatGPT 5