Train Scheduling
시간 제한2초메모리 제한1024 MB
두 역을 잇는 단일 선로에서 마주 오는 열차가 겹치지 않도록 N개 열차의 출발 시각을 미루어 총 지연 시간을 최소화한다.
문제
Bessie has taken on a new job as a train dispatcher! There are two train stations: and . Due to budget constraints, there is only a single track connecting the stations. If a train departs a station at time , then it will arrive at the other station at time ().
There are () trains whose departure times need to be scheduled. The th train must leave station at time or later (). 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 is scheduled to leave at time , the total delay is defined as .
입력
The first line contains and .
Then lines follow, where the th line contains the station and time corresponding to the th train.
출력
The minimum possible total delay over all valid schedules.