문제
Problem 1: Empty Stalls [Brian Dean, 2013]
Farmer John's new barn consists of a huge circle of N stalls
At the end of each day, FJ's cows arrive back at the barn one by one, each with a preferred stall they would like to occupy. However, if a cow's preferred stall is already occupied by another cow, she scans forward sequentially from this stall until she finds the first unoccupied stall, which she then claims. If she scans past stall N-1, she continues scanning from stall 0.
Given the preferred stall of each cow, please determine the smallest index of a stall that remains unoccupied after all the cows have returned to the barn. Notice that the answer to this question does not depend on the order in which the cows return to the barn.
In order to avoid issues with reading huge amounts of input, the input to this problem is specified in a concise format using K lines
X Y A B
One of these lines specifies the preferred stall for XY total cows: X cows prefer each of the stalls f(1) .. f(Y), where
Do not forget the standard memory limit of 64MB for all problems.
PROBLEM NAME: empty
SAMPLE INPUT (file empty.in):
10 3
3 2 2 4
2 1 0 1
1 1 1 7
INPUT DETAILS:
There are 10 stalls in the barn, numbered 0..9. The second line of input states that 3 cows prefer stall
SAMPLE OUTPUT (file empty.out):
5
OUTPUT DETAILS: All stalls will end up occupied except stall 5.
입력
* Line 1: Two space-separated integers: N and K.
* Lines
출력
* Line 1: The minimum index of an unoccupied stall.
예제1
103
3 2 2 4
2 1 0 1
1 1 1 7
5
INPUT DETAILS:
There are 10 stalls in the barn, numbered 0..9. The second line of input states that 3 cows prefer stall
OUTPUT DETAILS:
All stalls will end up occupied except stall 5.