← 返回 google 的题目列表Most Frequently Used Rental Car
类型:online_judge
Problem: Most Frequently Used Rental Car
There are k cars numbered from 0 to k - 1. You are given m rental requests. Each request is a half-open interval [start, end), meaning a customer wants to rent a car from start to end. The rental duration is end - start.
Requests are processed in ascending order of start. If multiple requests have the same start, process them in input order.
Assignment rules:
If at least one car is available at time start, assign the available car with the smallest id. The rental runs during [start, end).
If no car is available, delay the request until the earliest time t when a car becomes available. Assign the available car with the smallest id at that time. The duration remains unchanged, so the actual interval is [t, t + end - start).
Each assigned rental increases that car's usage count by 1.
Return the id of the car used the most often. If there is a tie, return the smallest id.
Input Format
k m
start end
start end
...
Output Format
Print one integer: the id of the most frequently used car.
Constraints
1 <= k <= 10^5
1 <= m <= 2 * 10^5
0 <= start < end <= 10^9
Example
Input:
2 4
0 10
1 5
2 7
3 4
Output:
0
Example
Input
2 4
0 10
1 5
2 7
3 4
Output
0