Roll Cake
Time limit1sMemory limit128 MB
Given N interval requests over pieces 1..L, find the member with the largest requested length, then the member who actually receives the most pieces when earlier requests get priority.
- Level
Easy3 of 10
- Topics
- Simulation, Array, Implementation
- Solved
- No attempts yet
Problem
A roll cake meters long is to be shared among audience members.
The cake is cut into -meter pieces. The leftmost piece is numbered and the rightmost piece is numbered . The audience members are numbered from to .
Each audience member writes two integers and on a slip of paper, meaning they want pieces through .
The host reads the slips in order, starting with member . When reading member 's slip, for each piece from to that has not yet been assigned to anyone, the host marks it with 's number and gives it to that member. Any piece already marked with another member's number is skipped. As a result, a member may not receive all of the pieces they asked for.
The figure below illustrates how the pieces are handed out.

The number of pieces member expects to receive equals the number of pieces they wrote down, that is . Write a program that finds the number of the member who expected to receive the most pieces, and the number of the member who actually received the most pieces.
Input
The first line contains the length of the roll cake ().
The second line contains the number of audience members ().
Each of the next lines contains the two integers and written by member ().
Output
On the first line, print the number of the member who expected to receive the most pieces.
On the second line, print the number of the member who actually received the most pieces.
In both cases, if more than one member satisfies the condition, print the smallest such member number.