AmazonOA #76
Get Min Time (Earliest Time Usage ≥ Max)
估计中等可在线判题
Each user contributes 1 usage at every integer second from start to end. Find the integer second at which the cumulative usage first reaches max_usage. CSWork standard I/O convention: output −1 if the threshold is never reached.
输入格式
The first line contains n max_usage (1≤n≤100000, 1≤max_usage≤10¹⁴), followed by n lines of start end (1≤start≤end≤10⁹).
输出格式
Output a single integer answer.
样例 1
输入:
2 3
1 3
2 2
输出:
2
样例 2
输入:
1 1
5 5
输出:
5
样例 3
输入:
1 2
1 1
输出:
-1
样例说明
Example 1: the cumulative total is 1 at second 1; at second 2 both users contribute 1 each, for a cumulative 3, so output 2. Example 2: starting and ending in the same second still contributes 1, and the threshold is first reached at second 5. Example 3: the total usage is only 1 and never reaches 2, so output −1 per this site's convention.