Apartment
InterviewTime limit1sMemory limit1024 MB
Given N and M participants with two hand heights each, find which participant drinks after the lowest hand is moved to the top N times.
- Level
Easy3 of 10
- Topics
- Sorting, Simulation
- Solved
- No attempts yet
Problem
Busan National University's Division of Computer Science and Engineering goes on a spring MT every year. Sanjini, a freshman who went on the spring MT, learned a drinking game called Apartment.
- The person who starts the game chooses the floor number of the apartment.
- Every participant stretches out both hands at heights that differ from everyone else's, so that all the participants' hands are stacked on top of each other.
- Take the lowest hand and place it on top of the stack.
- Repeat step 3 times. The hand stacked -th becomes floor .
- The participant who stacks floor drinks, and the game ends.
Sanjini wonders who will have to drink. Find out who will drink for Sanjini.
Input
The first line contains the floor number and the number of participants , separated by a space. ()
From the second line through line , the heights of the two hands and of participant are given, separated by a space. ()
No two hands have the same height. All input values are integers.
Output
Print the number of the participant who will drink.