Bus
Time limit2sMemory limit512 MB
Simulate bus boarding with passengers sitting in the closest free seat or standing over an occupied one, and choose Anton's seat minimizing the total time someone stands over him.
- Level
Hard8 of 10
- Topics
- Simulation, Greedy, Implementation, Intervals
- Solved
- No attempts yet
Statement
Every morning Anton takes the bus to work.
The bus route has stops, numbered from to in the order they are visited. The bus takes one minute to travel from each stop to the next, and its stopping time can be ignored. Anton boards at the first stop and gets off at the last one.
The bus has seats arranged in a single row and numbered from to ; the seat closest to the entrance is number , and the farthest is number . Each seat can hold one seated passenger, and one passenger can stand next to each seat.
When a person boards the bus, they sit in the free seat closest to the entrance. If all seats are taken, they look for the seat closest to the entrance that has no one standing next to it and stand over the person sitting there. If no such place exists, they get off the bus.
Every passenger stays in their place until the bus reaches their destination stop. A standing passenger keeps standing even if a seat becomes free.
At each stop, all passengers who intended to get off there leave the bus first, and only then do new passengers board.
Anton boarded the bus first, and he can sit in any seat and stay there until the end of the trip. He knows exactly who else will ride the bus: for every passenger, Anton knows at which stop they will board and at which stop they will get off. Help Anton choose a seat so that, over the course of the trip, the total time during which someone stands over him is as small as possible.
Input
The first line of the input contains three integers , , and : the number of stops, the number of seats on the bus, and the number of passengers other than Anton (, , ).
The next lines each contain two numbers and , meaning that the -th passenger intends to board at stop and get off at stop ().
If several people board the bus at the same stop, they board in the order in which they are listed in the input.
Output
Output two numbers on one line: the minimum total time in minutes during which someone stands over Anton, and the number of the seat he must take to achieve it. If there are several such seats, output the one closest to the entrance.