Waiting Line at the Cafeteria Entrance
InterviewTime limit0.1sMemory limit512 MB
Simulate a cafeteria entrance queue and report the peak line length with the back student's number, choosing the smallest number on ties.
- Level
Easy3 of 10
- Topics
- Queue, Simulation
- Solved
- No attempts yet
Problem
Several students are running toward the school cafeteria to eat. A student who reaches the cafeteria waits in a line at the entrance. A student who arrives earlier stands closer to the front of the line than a student who arrives later. Meals are prepared one portion at a time. When a portion is ready, the student at the front of the line enters the cafeteria and starts eating. A student who starts eating always finishes the meal.
You are given , which stores pieces of information about students arriving at the cafeteria and meals becoming ready. Process the 1st through -th pieces of information in order. Then output the number of students waiting in the entrance line at the moment that count was largest, along with the number of the student at the back of the line at that moment.
Each of the pieces of information in is one of the following two types.
- 1 : A student with the positive integer number arrives at the cafeteria and joins the back of the entrance line.
- 2: A meal portion is ready, and the student at the front of the entrance line starts eating.
Whenever a meal portion is ready, there is always a student waiting in the line. A student who is waiting in the line when no meal is ready does not eat.
Input
The first line contains . Each of the following lines contains one piece of information, which is either type 1 or type 2.
Output
Process the 1st through -th pieces of information in order. Then print two numbers separated by a space: the largest number of students waiting in the entrance line at any moment, and the number of the student at the back of the line at the moment that maximum occurred. If the maximum occurs more than once, print the case where the student at the back of the line has the smallest number.
Constraints
1 100,000
contains only type 1 and type 2 pieces of information.
1 , and all positive integers are distinct.