10427: USACO 2023 December Contest, Platinum Problem 3. Train Scheduling
Description
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)$.
Input
Then $N$ lines follow, where the $i$th line contains the station $s_i$ and time $t_i$ corresponding to the $i$th train.
Output
Sample 1 Input
1 95
B 63
Sample 1 Output
0
Sample 2 Input
4 1
B 3
B 2
A 1
A 3
Sample 2 Output
1
Sample 3 Input
4 10
A 1
B 2
A 3
A 21
Sample 3 Output
13
8 125000000000
B 17108575619
B 57117098303
A 42515717584
B 26473500855
A 108514697534
B 110763448122
B 117731666682
A 29117227954
548047356974