This page is still under construction.

Parts of this page are still being built. What you see may change.

Universal and Existential Quantifiers

Interview

Time limit2sMemory limit512 MB

Summary
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 NN intervals. The ii-th interval is \[li,ri)\[l_i,r_i), which denotes the range of numbers greater than or equal to lil_i and strictly less than rir_i. In this task, you consider the following two numbers:

  • The minimum integer xx such that you can select xx intervals from the given NN intervals so that the union of the selected intervals is \[0,L)\[0,L).
  • The minimum integer yy such that no matter how you choose yy intervals from the given NN intervals, the chosen intervals cover \[0,L)\[0,L).

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 NN (1≤N≤2⋅1051 \le N \le 2 \cdot 10^5) and LL (1≤L≤10121 \le L \le 10^{12}), where NN is the number of intervals and LL is the length of the range to be covered. The ii-th of the following NN lines contains two integers lil_i and rir_i (0≤li<ri≤L0 \le l_i < r_i \le L), representing the range of the ii-th interval \[li,ri)\[l_i,r_i). You can assume that the union of all the NN intervals is \[0,L)\[0,L).

Output

Output the two integers xx and yy defined in the problem statement, separated by a single space, on one line.

Examples3

  1. Example 1

    Input
    3 3
    0 2
    1 3
    1 2
    
    Expected output
    2 3
    
  2. Example 2

    Input
    2 4
    0 4
    0 4
    
    Expected output
    1 1
    
  3. Example 3

    Input
    5 4
    0 2
    2 4
    0 3
    1 3
    3 4
    
    Expected output
    2 4