Universal and Existential Quantifiers
InterviewTime limit2sMemory limit512 MB
Given N half-open intervals whose union is [0,L), find the fewest intervals whose union is [0,L) and the fewest k such that any k intervals already cover [0,L).
- Level
Hard8 of 10
- Topics
- Greedy, Sorting, Intervals, Binary search
- Solved
- No attempts yet
Problem
You are given a list of intervals. The -th interval is , which denotes the range of numbers greater than or equal to and strictly less than . In this task, you consider the following two numbers:
- The minimum integer such that you can select intervals from the given intervals so that the union of the selected intervals is .
- The minimum integer such that no matter how you choose intervals from the given intervals, the chosen intervals cover .
Write a program to compute these two numbers.
Input
The input consists of a single test case formatted as follows.
The first line contains two integers () and (), where is the number of intervals and is the length of the range to be covered. The -th of the following lines contains two integers and (), representing the range of the -th interval . You can assume that the union of all the intervals is .
Output
Output the two integers and defined in the problem statement, separated by a single space, on one line.