Problem:
Problem Statement
You are given a list of $N$ intervals. The $i$-th interval is $[l_i, r_i)$, which denotes a range of numbers greater than or equal to $l_i$ and strictly less than $r_i$. In this task, you consider the following two numbers:
The minimum integer $x$ such that you can select $x$ intervals from the given $N$ intervals so that the union of the selected intervals is $[0, L)$.
The minimum integer $y$ such that for all possible combinations of $y$ intervals from the given $N$ interval, it
does
cover $[0, L)$.
We ask you to write a program to compute these two numbers.
Input
The input consists of a single test case formatted as follows.
$N$ $L$
$l_1$ $r_1$
$l_2$ $r_2$
$\vdots$
$l_N$ $r_N$
The first line contains two integers $N$ ($1 \leq N \leq 2 \times 10^5$) and $L$ ($1 \leq L \leq 10^{12}$), where $N$ is the number of intervals and $L$ is the length of range to be covered, respectively. The $i$-th of the following $N$ lines contains two integers $l_i$ and $r_i$ ($0 \leq l_i < r_i \leq L$), representing the range of the $i$-th interval $[l_i, r_i)$. You can assume that the union of all the $N$ intervals is $[0, L)$
Output
Output two integers $x$ and $y$ mentioned in the problem statement, separated by a single space, in a line.
Examples
Input
Output
3 3
0 2
1 3
1 2
2 3
2 4
0 4
0 4
1 1
5 4
0 2
2 4
0 3
1 3
3 4
2 4

Submitted solutions:

code_snippet: #include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rrep(i,start,end) for (ll i = start;i >= (ll)(end);i--)
#define repn(i,end) for(ll i = 0; i <= (ll)(end); i++)
#define reps(i,start,end) for(ll i = start; i < (ll)(end); i++)
#define repsn(i,start,end) for(ll i = start; i <= (ll)(end); i++)
#define each(p,a) for(auto &p:a)
typedef vector<ll> vll;
typedef vector<pair<ll ,ll>> vpll;
typedef vector<vector<pair<ll ,ll>>> vvpll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;
typedef set<ll> sll;
typedef map<ll , ll> mpll;
typedef pair<ll ,ll> pll;
typedef tuple<ll , ll , ll> tpl3;
typedef tuple<ll , ll , ll , ll> tpl4;
typedef tuple<ll , ll , ll , ll , ll> tpl5;
typedef tuple<ll , ll , ll , ll , ll , ll> tpl6;
#define LL(...) ll __VA_ARGS__; input(__VA_ARGS__)
#define LD(...) ld __VA_ARGS__; input(__VA_ARGS__)
#define Str(...) string __VA_ARGS__; input(__VA_ARGS__)
#define Ch(...) char __VA_ARGS__; input(__VA_ARGS__)
#define all(a)  (a).begin(),(a).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define sz(x) (ll)x.size()
// << std::fixed << std::setprecision(10)
const ll INF = 1LL << 60;
const ld EPS = 1e-9;
 
ll lceil(ll a,ll b){if(a%b==0){return a/b;}if(a>=0){return (a/b)+1;}else{return -((-a)/b);}}
ll lfloor(ll a,ll b){if(a%b==0){return a/b;}if(a>=0){return (a/b);}else{return -((-a)/b)-1;}}
inline ll positive_mod(ll a,ll m){return (a % m + m)%m;}
inline ll popcnt(ull a){ return __builtin_popcountll(a);}
//0indexed
inline ll topbit(ll a){assert(a != 0);return 63 - __builtin_clzll(a);}
inline ll smlbit(ll a){assert(a != 0);return __builtin_ctzll(a);}
template<class T> bool chmin(T& a, T b){if(a > b){a = b;return true;}return false;}
template<class T> bool chmax(T& a, T b){if(a < b){a = b;return true;}return false;}
template<typename T> std::istream &operator>>(std::istream&is,std::vector<T>&v){for(T &in:v){is>>in;}return is;}
template<typename T> std::ostream &operator<<(std::ostream&os,const std::vector<T>&v){for(auto it=std::begin(v);it!=std::end(v);){os<<*it<<((++it)!=std::end(v)?" ":"");}return os;}
template<typename T1, typename T2>std::ostream &operator<< (std::ostream &os, std::pair<T1,T2> p){os << "{" << p.first << "," << p.second << "}";return os;}
template<class... T>void input(T&... a){(cin >> ... >> a);}
void print(){cout << endl;}
template<class T, class... Ts>void print(const T& a, const Ts&... b){cout << a;((cout << ' ' << b), ...);cout << endl;}
template<class T> void pspace(const T& a){ cout << a << ' ';}
void perr(){cerr << endl;}
template<class T, class... Ts>void perr(const T& a, const Ts&... b){cerr << a;((cerr << ' ' << b), ...);cerr << endl;}
void yes(bool i = true){ return print(i?"yes":"no"); }
void Yes(bool i = true){ return print(i?"Yes":"No"); }
void YES(bool i = true){ return print(i?"YES":"NO"); }
template <class T> vector<T> &operator++(vector<T> &v) {for(auto &e : v) e++;return v;}
template <class T> vector<T> operator++(vector<T> &v, signed) {auto res = v;for(auto &e : v) e++;return res;}
template <class T> vector<T> &operator--(vector<T> &v) {for(auto &e : v) e--;return v;}
template <class T> vector<T> operator--(vector<T> &v, signed) {auto res = v;for(auto &e : v) e--;return res;}
//grid探索用
vector<ll> _ta = {0,0,1,-1,1,1,-1,-1};
vector<ll> _yo = {1,-1,0,0,1,-1,1,-1};
bool isin(ll now_i,ll now_j,ll h,ll w){return (0<=now_i && now_i < h && 0 <= now_j && now_j < w);}
  
ll lpow(ll x,ll n){ll ans = 1;while(n >0){if(n & 1)ans *= x;x *= x;n >>= 1;}return ans;}
ll Modlpow(ll x,ll n,ll m){ll ans = 1;ll a = x%m;while(n >0){if(n & 1){ans *= a;ans%= m;}a *= a;a %= m;n >>= 1;}return ans;} 
const ll MOD9 = 998244353LL;
const ll MOD10 = 1000000007LL;

template<class T>
struct SegmentTree{
  vector<T> tree;
  ll siz = 0;
  T e;
  function<T(T,T)> op;
  function<T(T,T)> mapping = [](T a,T b){return b;};

  SegmentTree(ll n,T _e,function<T(T,T)> _op):e(_e),op(_op){
    ll i = 0;
    while((1<<i)<n){
      i++;
    }
    tree.resize(1<<(i+1),e);
    siz = 1 << i;
  }
  void update(ll pos, T x){
    pos = pos + siz-1;
    tree[pos] = mapping(tree[pos],x);
    while(pos >= 1){
      pos = (pos-1)/2;
      tree[pos] = op(tree[2*pos+1],tree[2*(pos+1)]);
    }
  }

  T _query(ll l,ll r,ll a,ll b,ll p){
    if(r <= a or l >= b){
      return e;
    }
    if(l <= a and b <= r){
      return tree[p];
    }
    ll m = (a+b)/2;
    T ansl = _query(l,r,a,m,2*p+1);
    T ansr = _query(l,r,m,b,2*(p+1));
    return op(ansl,ansr);
  }
  T query(ll l,ll r){
    return _query(l,r,0,siz,0);
  }

  T operator[](ll pos){
    return tree[pos+siz-1];
  }
};
 
int main(){
  ios::sync_with_stdio(false);cin.tie(nullptr);
  LL(n,L);
  vll ord;
  vpll lr(n);
  rep(i,n){
    LL(l,r);
    ord.push_back(l);
    ord.push_back(r);
    lr[i] = {l,r};
  }
  sort(all(ord));
  UNIQUE(ord);
  rep(i,n){
    auto [l,r] = lr[i];
    l = lower_bound(all(ord),l) -ord.begin();
    r = lower_bound(all(ord),r) - ord.begin();
    lr[i] = {l,r};
  }
  auto cmp = [&](pll u,pll v){
    if(u.second != v.second){
      return u.second < v.second;
    }else return u.first < v.first;
  };
  sort(all(lr),cmp);
  vll sum(sz(ord));
  auto op = [](ll u, ll v){return min(u,v);};
  SegmentTree<ll>seg(sz(ord)+1,INF,op);
  seg.update(0,0);
  rep(i,n){
    auto [l,r] = lr[i];
    seg.update(r,min(seg.query(l,r)+1,seg[r]));
    sum[l]++;
    sum[r]--;
  }
  rep(i,sz(ord)-1){
    sum[i+1]+= sum[i];
  }
  ll mi = INF;
  rep(i,sz(ord)-1){
    chmin(mi,sum[i]);
  }
  cout << seg[sz(ord)-1] << " " << n-mi+1 << endl;

}
accuracy: 1
time_ms: 120
memory_kb: 21396
final_rank: 4

code_snippet: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rrep(i,start,end) for (ll i = start;i >= (ll)(end);i--)
#define repn(i,end) for(ll i = 0; i <= (ll)(end); i++)
#define reps(i,start,end) for(ll i = start; i < (ll)(end); i++)
#define repsn(i,start,end) for(ll i = start; i <= (ll)(end); i++)
#define each(p,a) for(auto &p:a)
typedef vector<ll> vll;
typedef vector<pair<ll ,ll>> vpll;
typedef vector<vector<pair<ll ,ll>>> vvpll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;
typedef set<ll> sll;
typedef map<ll , ll> mpll;
typedef pair<ll ,ll> pll;
typedef tuple<ll , ll , ll> tpl3;
typedef tuple<ll , ll , ll , ll> tpl4;
typedef tuple<ll , ll , ll , ll , ll> tpl5;
typedef tuple<ll , ll , ll , ll , ll , ll> tpl6;
#define LL(...) ll __VA_ARGS__; input(__VA_ARGS__)
#define LD(...) ld __VA_ARGS__; input(__VA_ARGS__)
#define Str(...) string __VA_ARGS__; input(__VA_ARGS__)
#define Ch(...) char __VA_ARGS__; input(__VA_ARGS__)
#define all(a)  (a).begin(),(a).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define sz(x) (ll)x.size()
// << std::fixed << std::setprecision(10)
const ll INF = 1LL << 60;
const ld EPS = 1e-9;
 
ll lceil(ll a,ll b){if(a%b==0){return a/b;}if(a>=0){return (a/b)+1;}else{return -((-a)/b);}}
ll lfloor(ll a,ll b){if(a%b==0){return a/b;}if(a>=0){return (a/b);}else{return -((-a)/b)-1;}}
inline ll positive_mod(ll a,ll m){return (a % m + m)%m;}
inline ll popcnt(ull a){ return __builtin_popcountll(a);}
//0indexed
inline ll topbit(ll a){assert(a != 0);return 63 - __builtin_clzll(a);}
inline ll smlbit(ll a){assert(a != 0);return __builtin_ctzll(a);}
template<class T> bool chmin(T& a, T b){if(a > b){a = b;return true;}return false;}
template<class T> bool chmax(T& a, T b){if(a < b){a = b;return true;}return false;}
template<typename T> std::istream &operator>>(std::istream&is,std::vector<T>&v){for(T &in:v){is>>in;}return is;}
template<typename T> std::ostream &operator<<(std::ostream&os,const std::vector<T>&v){for(auto it=std::begin(v);it!=std::end(v);){os<<*it<<((++it)!=std::end(v)?" ":"");}return os;}
template<typename T1, typename T2>std::ostream &operator<< (std::ostream &os, std::pair<T1,T2> p){os << "{" << p.first << "," << p.second << "}";return os;}
template<class... T>void input(T&... a){(cin >> ... >> a);}
void print(){cout << endl;}
template<class T, class... Ts>void print(const T& a, const Ts&... b){cout << a;((cout << ' ' << b), ...);cout << endl;}
template<class T> void pspace(const T& a){ cout << a << ' ';}
void perr(){cerr << endl;}
template<class T, class... Ts>void perr(const T& a, const Ts&... b){cerr << a;((cerr << ' ' << b), ...);cerr << endl;}
void yes(bool i = true){ return print(i?"yes":"no"); }
void Yes(bool i = true){ return print(i?"Yes":"No"); }
void YES(bool i = true){ return print(i?"YES":"NO"); }
template <class T> vector<T> &operator++(vector<T> &v) {for(auto &e : v) e++;return v;}
template <class T> vector<T> operator++(vector<T> &v, signed) {auto res = v;for(auto &e : v) e++;return res;}
template <class T> vector<T> &operator--(vector<T> &v) {for(auto &e : v) e--;return v;}
template <class T> vector<T> operator--(vector<T> &v, signed) {auto res = v;for(auto &e : v) e--;return res;}
//grid探索用
vector<ll> _ta = {0,0,1,-1,1,1,-1,-1};
vector<ll> _yo = {1,-1,0,0,1,-1,1,-1};
bool isin(ll now_i,ll now_j,ll h,ll w){return (0<=now_i && now_i < h && 0 <= now_j && now_j < w);}
  
ll lpow(ll x,ll n){ll ans = 1;while(n >0){if(n & 1)ans *= x;x *= x;n >>= 1;}return ans;}
ll Modlpow(ll x,ll n,ll m){ll ans = 1;ll a = x%m;while(n >0){if(n & 1){ans *= a;ans%= m;}a *= a;a %= m;n >>= 1;}return ans;} 
const ll MOD9 = 998244353LL;
const ll MOD10 = 1000000007LL;

template<class T>
struct SegmentTree{
  vector<T> tree;
  ll siz = 0;
  T e;
  function<T(T,T)> op;
  function<T(T,T)> mapping = [](T a,T b){return b;};

  SegmentTree(ll n,T _e,function<T(T,T)> _op):e(_e),op(_op){
    ll i = 0;
    while((1<<i)<n){
      i++;
    }
    tree.resize(1<<(i+1),e);
    siz = 1 << i;
  }
  void update(ll pos, T x){
    pos = pos + siz-1;
    tree[pos] = mapping(tree[pos],x);
    while(pos >= 1){
      pos = (pos-1)/2;
      tree[pos] = op(tree[2*pos+1],tree[2*(pos+1)]);
    }
  }

  T _query(ll l,ll r,ll a,ll b,ll p){
    if(r <= a or l >= b){
      return e;
    }
    if(l <= a and b <= r){
      return tree[p];
    }
    ll m = (a+b)/2;
    T ansl = _query(l,r,a,m,2*p+1);
    T ansr = _query(l,r,m,b,2*(p+1));
    return op(ansl,ansr);
  }
  T query(ll l,ll r){
    return _query(l,r,0,siz,0);
  }

  T operator[](ll pos){
    return tree[pos+siz-1];
  }
};
 
int main(){
  ios::sync_with_stdio(false);cin.tie(nullptr);
  LL(n,L);
  vll ord;
  vpll lr(n);
  rep(i,n){
    LL(l,r);
    ord.push_back(l);
    ord.push_back(r);
    lr[i] = {l,r};
  }
  sort(all(ord));
  UNIQUE(ord);
  rep(i,n){
    auto [l,r] = lr[i];
    l = lower_bound(all(ord),l) -ord.begin();
    r = lower_bound(all(ord),r) - ord.begin();
    lr[i] = {l,r};
  }
  auto cmp = [&](pll u,pll v){
    if(u.second != v.second){
      return u.second < v.second;
    }else return u.first < v.first;
  };
  sort(all(lr),cmp);
  vll sum(sz(ord));
  auto op = [](ll u, ll v){return min(u,v);};
  SegmentTree<ll>seg(sz(ord)+1,INF,op);
  seg.update(0,0);
  rep(i,n){
    auto [l,r] = lr[i];
    seg.update(r,min(seg.query(l,r)+1,seg[r]));
    sum[l]++;
    sum[r]--;
  }
  rep(i,sz(ord)-1){
    sum[i+1]+= sum[i];
  }
  ll mi = INF;
  rep(i,sz(ord)-1){
    chmin(mi,sum[i]);
  }
  cout << seg[sz(ord)-1] << " " << n-mi+1 << endl;

}
accuracy: 1
time_ms: 120
memory_kb: 21264
final_rank: 3

code_snippet: #include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rrep(i,start,end) for (ll i = start;i >= (ll)(end);i--)
#define repn(i,end) for(ll i = 0; i <= (ll)(end); i++)
#define reps(i,start,end) for(ll i = start; i < (ll)(end); i++)
#define repsn(i,start,end) for(ll i = start; i <= (ll)(end); i++)
#define each(p,a) for(auto &p:a)
typedef vector<ll> vll;
typedef vector<pair<ll ,ll>> vpll;
typedef vector<vector<pair<ll ,ll>>> vvpll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;
typedef set<ll> sll;
typedef map<ll , ll> mpll;
typedef pair<ll ,ll> pll;
typedef tuple<ll , ll , ll> tpl3;
typedef tuple<ll , ll , ll , ll> tpl4;
typedef tuple<ll , ll , ll , ll , ll> tpl5;
typedef tuple<ll , ll , ll , ll , ll , ll> tpl6;
#define LL(...) ll __VA_ARGS__; input(__VA_ARGS__)
#define LD(...) ld __VA_ARGS__; input(__VA_ARGS__)
#define Str(...) string __VA_ARGS__; input(__VA_ARGS__)
#define Ch(...) char __VA_ARGS__; input(__VA_ARGS__)
#define all(a)  (a).begin(),(a).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define sz(x) (ll)x.size()
// << std::fixed << std::setprecision(10)
const ll INF = 1LL << 60;
const ld EPS = 1e-9;
 
ll lceil(ll a,ll b){if(a%b==0){return a/b;}if(a>=0){return (a/b)+1;}else{return -((-a)/b);}}
ll lfloor(ll a,ll b){if(a%b==0){return a/b;}if(a>=0){return (a/b);}else{return -((-a)/b)-1;}}
inline ll positive_mod(ll a,ll m){return (a % m + m)%m;}
inline ll popcnt(ull a){ return __builtin_popcountll(a);}
//0indexed
inline ll topbit(ll a){assert(a != 0);return 63 - __builtin_clzll(a);}
inline ll smlbit(ll a){assert(a != 0);return __builtin_ctzll(a);}
template<class T> bool chmin(T& a, T b){if(a > b){a = b;return true;}return false;}
template<class T> bool chmax(T& a, T b){if(a < b){a = b;return true;}return false;}
template<typename T> std::istream &operator>>(std::istream&is,std::vector<T>&v){for(T &in:v){is>>in;}return is;}
template<typename T> std::ostream &operator<<(std::ostream&os,const std::vector<T>&v){for(auto it=std::begin(v);it!=std::end(v);){os<<*it<<((++it)!=std::end(v)?" ":"");}return os;}
template<typename T1, typename T2>std::ostream &operator<< (std::ostream &os, std::pair<T1,T2> p){os << "{" << p.first << "," << p.second << "}";return os;}
template<class... T>void input(T&... a){(cin >> ... >> a);}
void print(){cout << endl;}
template<class T, class... Ts>void print(const T& a, const Ts&... b){cout << a;((cout << ' ' << b), ...);cout << endl;}
template<class T> void pspace(const T& a){ cout << a << ' ';}
void perr(){cerr << endl;}
template<class T, class... Ts>void perr(const T& a, const Ts&... b){cerr << a;((cerr << ' ' << b), ...);cerr << endl;}
void yes(bool i = true){ return print(i?"yes":"no"); }
void Yes(bool i = true){ return print(i?"Yes":"No"); }
void YES(bool i = true){ return print(i?"YES":"NO"); }
template <class T> vector<T> &operator++(vector<T> &v) {for(auto &e : v) e++;return v;}
template <class T> vector<T> operator++(vector<T> &v, signed) {auto res = v;for(auto &e : v) e++;return res;}
template <class T> vector<T> &operator--(vector<T> &v) {for(auto &e : v) e--;return v;}
template <class T> vector<T> operator--(vector<T> &v, signed) {auto res = v;for(auto &e : v) e--;return res;}
//grid探索用
vector<ll> _ta = {0,0,1,-1,1,1,-1,-1};
vector<ll> _yo = {1,-1,0,0,1,-1,1,-1};
bool isin(ll now_i,ll now_j,ll h,ll w){return (0<=now_i && now_i < h && 0 <= now_j && now_j < w);}
  
ll lpow(ll x,ll n){ll ans = 1;while(n >0){if(n & 1)ans *= x;x *= x;n >>= 1;}return ans;}
ll Modlpow(ll x,ll n,ll m){ll ans = 1;ll a = x%m;while(n >0){if(n & 1){ans *= a;ans%= m;}a *= a;a %= m;n >>= 1;}return ans;} 
const ll MOD9 = 998244353LL;
const ll MOD10 = 1000000007LL;

template<class T>
struct SegmentTree{
  vector<T> tree;
  ll siz = 0;
  T e;
  function<T(T,T)> op;
  function<T(T,T)> mapping = [](T a,T b){return b;};

  SegmentTree(ll n,T _e,function<T(T,T)> _op):e(_e),op(_op){
    ll i = 0;
    while((1<<i)<n){
      i++;
    }
    tree.resize(1<<(i+1),e);
    siz = 1 << i;
  }
  void update(ll pos, T x){
    pos = pos + siz-1;
    tree[pos] = mapping(tree[pos],x);
    while(pos >= 1){
      pos = (pos-1)/2;
      tree[pos] = op(tree[2*pos+1],tree[2*(pos+1)]);
    }
  }

  T _query(ll l,ll r,ll a,ll b,ll p){
    if(r <= a or l >= b){
      return e;
    }
    if(l <= a and b <= r){
      return tree[p];
    }
    ll m = (a+b)/2;
    T ansl = _query(l,r,a,m,2*p+1);
    T ansr = _query(l,r,m,b,2*(p+1));
    return op(ansl,ansr);
  }
  T query(ll l,ll r){
    return _query(l,r,0,siz,0);
  }

  T operator[](ll pos){
    return tree[pos+siz-1];
  }
};
 
int main(){
  ios::sync_with_stdio(false);cin.tie(nullptr);
  LL(n,L);
  vll ord;
  vpll lr(n);
  rep(i,n){
    LL(l,r);
    ord.push_back(l);
    ord.push_back(r);
    lr[i] = {l,r};
  }
  sort(all(ord));
  UNIQUE(ord);
  rep(i,n){
    auto [l,r] = lr[i];
    l = lower_bound(all(ord),l) -ord.begin();
    r = lower_bound(all(ord),r) - ord.begin();
    lr[i] = {l,r};
  }
  auto cmp = [&](pll u,pll v){
    if(u.second != v.second){
      return u.second < v.second;
    }else return u.first < v.second;
  };
  sort(all(lr),cmp);
  vll sum(sz(ord));
  auto op = [](ll u, ll v){return min(u,v);};
  SegmentTree<ll>seg(sz(ord)+1,INF,op);
  seg.update(0,0);
  rep(i,n){
    auto [l,r] = lr[i];
    seg.update(r,min(seg.query(l,r)+1,seg[r]));
    sum[l]++;
    sum[r]--;
  }
  rep(i,sz(ord)-1){
    sum[i+1]+= sum[i];
  }
  ll mi = INF;
  rep(i,sz(ord)-1){
    chmin(mi,sum[i]);
  }
  cout << seg[sz(ord)-1] << " " << n-mi+1 << endl;

}
accuracy: 0.4925373134328358
time_ms: 130
memory_kb: 21300
final_rank: 17

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using a2 = array<ll, 2>;
using a3 = array<ll, 3>;

bool chmin(auto& a, const auto& b) { return a > b ? a = b, 1 : 0; }
bool chmax(auto& a, const auto& b) { return a < b ? a = b, 1 : 0; }

const ll INF = 1e18;
ll mod = 998244353;

ifstream in;
ofstream out;

int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);

    if (argc > 2) {
        in.open(argv[1]);
        cin.rdbuf(in.rdbuf());
        out.open(argv[2]);
        cout.rdbuf(out.rdbuf());
    }

    ll n, l;
    cin >> n >> l;
    vector<a2> v(n);
    for (auto& x : v) cin >> x[0] >> x[1];

    sort(v.begin(), v.end());

    ll ansx = 0;
    ll now = 0, mx = 0;
    for (int i = 0; i < n; i++) {
        if (v[i][0] > now) {
            now = mx;
            ansx++;
        }
        chmax(mx, v[i][1]);
    }
    ansx += now < l;

    vector<ll> zaatsu;
    for (int i = 0; i < n; i++) {
        zaatsu.push_back(v[i][0]);
        zaatsu.push_back(v[i][1]);
    }
    sort(zaatsu.begin(), zaatsu.end());
    zaatsu.erase(unique(zaatsu.begin(), zaatsu.end()), zaatsu.end());
    map<ll, ll> mp;
    for (int i = 0; i < zaatsu.size(); i++) {
        mp[zaatsu[i]] = i;
    }

    vector<ll> sum(zaatsu.size() + 1, 0);
    for (int i = 0; i < n; i++) {
        sum[mp[v[i][0]]]++;
        sum[mp[v[i][1]] + 1]--;
    }
    for (int i = 1; i < sum.size(); i++) {
        sum[i] += sum[i - 1];
    }

    cout << ansx << ' ' << n - *min_element(sum.begin(), sum.end() - 1) + 1 << endl;

    return 0;
}
accuracy: 1
time_ms: 200
memory_kb: 36472
final_rank: 13

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define vl vector<ll>
#define vvl vector<vl>
using PLL = pair<ll, ll>;
#define rep(i, n) for (ll i = 0; i < n; ++i)
constexpr ll INF = 9009009009009009009LL;

int main() {
    ll n, L; cin >> n >> L;
    vector<PLL> lr(n);
    rep(i, n) {
        ll l, r; cin >> l >> r;
        lr[i] = {l, r};
    }
    
    // x
    priority_queue<PLL, vector<PLL>, greater<PLL>> lq;
    priority_queue<ll> rq;
    rep(i, n) {
        lq.push({lr[i].first, lr[i].second});
    }
    
    ll now = 0;
    ll x = 0;
    while (now < L) {
        while (!lq.empty() && lq.top().first <= now) {
            rq.push(lq.top().second);
            lq.pop();
        }
        
        now = rq.top();
        x++;
        rq.pop();
    }
    cout << x << " ";

    // y
    map<ll, ll> mp;
    rep(i, n) {
        mp[lr[i].first] = 0;
        mp[lr[i].second] = 0;
    }
    auto it = mp.begin();
    for (ll i = 0; it != mp.end(); ++it, ++i) {
        it->second = i;
    }

    vl imos(mp.rbegin()->second + 1, 0);
    rep(i, n) {
        imos[mp[lr[i].first]] += 1;
        imos[mp[lr[i].second]] -= 1;
    }

    ll mn = INF;
    ll sum = 0;
    rep(i, mp.rbegin()->second) {
        sum += imos[i];
        mn = min(mn, sum);
    }

    cout << n - mn + 1 << endl;
}
accuracy: 1
time_ms: 340
memory_kb: 39064
final_rank: 16

code_snippet: #include<bits/stdc++.h>
// #include<atcoder/all>
// #include<boost/multiprecision/cpp_int.hpp>

using namespace std;
// using namespace atcoder;
// using bint = boost::multiprecision::cpp_int;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<ll>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using ve = vector<vector<int>>;
using vb = vector<bool>;
using vvb = vector<vb>;
#define rep(i,s,n) for(ll i = (ll)s;i < (ll)n;i++)
#define rrep(i,l,r) for(ll i = r-1;i >= l;i--)
#define ALL(x) (x).begin(),(x).end()
#define sz(c) ((ll)(c).size())
#define LB(A,x) (int)(lower_bound(A.begin(),A.end(),x)-A.begin())
#define UB(A,x) (int)(upper_bound(A.begin(),A.end(),x)-A.begin())
// #define MOD 1000000007
#define MOD 998244353
template<typename T>using min_priority_queue=priority_queue<T,vector<T>,greater<T>>;
template<typename T>ostream&operator<<(ostream&os,vector<T>&v){for(int i = 0;i < v.size();i++)os<<v[i]<<(i+1!=v.size()?" ":"");return os;}
template<typename T>istream&operator>>(istream&is,vector<T>&v){for(T&in:v)is>>in;return is;}
template<typename T1,typename T2>ostream&operator<<(ostream&os,pair<T1,T2>&p){os<<p.first<<" "<<p.second;return os;}
template<typename T1,typename T2>istream&operator>>(istream&is,pair<T1,T2>&p){is>>p.first>>p.second;return is;}
template<typename T> inline bool chmax(T &a,T b){if(a < b){a = b;return true;}return false;}
template<typename T> inline bool chmin(T &a,T b){if(a > b){a = b;return true;}return false;}
ld dist(ld x1,ld y1,ld x2, ld y2){return sqrtl((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));}


int main(){
  
  ios_base::sync_with_stdio(0), cin.tie(0);
  ll n,L;cin >> n >> L;
  vi cor;
  vi l(n),r(n);
  rep(i,0,n)cin >> l[i] >> r[i];
  rep(i,0,n)rep(k,-1,2){
    if(l[i]+k >= 0)cor.emplace_back(l[i]+k);
    if(r[i]+k < L)cor.emplace_back(r[i]+k);
  }
  cor.emplace_back(L);
  sort(ALL(cor));
  cor.erase(unique(ALL(cor)),cor.end());
  vi v(sz(cor),-1);
  rep(i,0,n)chmax(v[LB(cor,l[i])],1ll*LB(cor,r[i]));
  ll cl = 0,ln = v[0];
  ll x = 0;
  while(cor[cl] < L){
    x++;
    ll LN = 0;
    rep(i,cl,ln+1)chmax(LN,v[i]);
    cl = ln;ln = LN;
  }
  rep(i,0,n)l[i] = LB(cor,l[i]);
  rep(i,0,n)r[i] = LB(cor,r[i]);
  sort(ALL(l));sort(ALL(r));
  ll y = 0;
  rep(i,0,sz(cor)-1){
    chmax(y,n-LB(l,i+1) + LB(r,i+1)  + 1);
  }
  cout << x << " " << y << endl;
  

  return 0;
}
accuracy: 1
time_ms: 230
memory_kb: 25944
final_rank: 8

code_snippet: #include <bits/stdc++.h>
using namespace std;

using ll = long long;

void compress(vector<ll>& xs) {
    sort(xs.begin(), xs.end());
    xs.erase(unique(xs.begin(), xs.end()), xs.end());
}

int main() {
    ll n, L; cin >> n >> L;
    vector<ll> l(n), r(n);
    vector<ll> not_cover_cand, ps;
    for(int i = 0; i < n; ++i) {
        cin >> l[i] >> r[i];
        ps.push_back(l[i]);
        ps.push_back(r[i]);
        if(l[i] != 0) {
            not_cover_cand.push_back(l[i] - 1);
            ps.push_back(l[i] - 1);
        }
        if(r[i] != L) {
            not_cover_cand.push_back(r[i]);
        }
    }
    compress(ps);
    compress(not_cover_cand);

    const int m = ps.size();
    vector<ll> max_to(ps.size(), -1);
    for(int i = 0; i < n; ++i) {
        l[i] = lower_bound(ps.begin(), ps.end(), l[i]) - ps.begin();
        r[i] = lower_bound(ps.begin(), ps.end(), r[i]) - ps.begin();
        max_to[l[i]] = max(max_to[l[i]], r[i]);
    }
    for(int i = 0; i + 1 < m; ++i) {
        max_to[i + 1] = max(max_to[i + 1], max_to[i]);
    }

    int x = 0;
    for(ll i = 0, cur = 0; i < m && cur != m - 1; ++i) {
        x += 1;
        cur = max_to[cur];
    }

    vector<int> sum_l(m + 1), sum_r(m + 1);
    for(int i = 0; i < n; ++i) {
        sum_l[r[i]] += 1;
        if(l[i] != 0) {
            sum_r[l[i] - 1] += 1;
        }
    }
    for(int i = 0; i < m; ++i) {
        sum_l[i + 1] += sum_l[i];
    }
    for(int i = m - 1; i >= 0; --i) {
        sum_r[i] += sum_r[i + 1];
    }
    int y = 0;
    for(auto p : not_cover_cand) {
        p = lower_bound(ps.begin(), ps.end(), p) - ps.begin();
        //cout << ps[p] << " " << " -> " << sum_l[p] << " " << sum_r[p] << endl;
        y = max(y, sum_l[p] + sum_r[p]);
    }
    cout << x << " " << y + 1 << endl;
}
accuracy: 1
time_ms: 200
memory_kb: 23344
final_rank: 5

code_snippet: #include <iostream>
#include <iomanip>
#include <cassert>
#include <vector>
#include <algorithm>
#include <utility>
#include <numeric>
#include <tuple>
// #include "Src/Number/IntegerDivision.hpp"
// #include "Src/Utility/BinarySearch.hpp"
// #include "Src/Sequence/CompressedSequence.hpp"
// #include "Src/Sequence/RunLengthEncoding.hpp"
// #include "Src/Algebra/Group/AdditiveGroup.hpp"
// #include "Src/DataStructure/FenwickTree/FenwickTree.hpp"
// using namespace zawa;
// #include "atcoder/modint"
// using mint = atcoder::modint998244353;
#include <queue>
int N;
long long P, L[200020], R[200020];
long long solveX() {
    std::vector<std::pair<long long, long long>> LR(N);
    for (int i = 0 ; i < N ; i++) LR[i] = {L[i], R[i]};
    std::sort(LR.begin(), LR.end());
    int idx = 0;
    std::priority_queue<long long> que;
    while (idx < N and LR[idx].first == 0) {
        que.push(LR[idx].second);
        idx++;
    }
    int ans = 0;
    while (true) {
        assert(que.size());
        ans++;
        long long r = que.top();
        que.pop();
        if (r == P) break;
        while (idx < N and LR[idx].first <= r) {
            que.push(LR[idx].second);
            idx++;
        }
    }
    return ans;
}
long long solveY() {
    std::vector<long long> app(N + N);
    for (int i = 0 ; i < N ; i++) {
        app[i] = L[i];
        app[i + N] = R[i];
    }
    std::sort(app.begin(), app.end());
    app.erase(std::unique(app.begin(), app.end()), app.end());
    std::vector<int> cl(app.size()), cr(app.size());
    for (int i = 0 ; i < N ; i++) {
        cl[std::lower_bound(app.begin(), app.end(), L[i]) - app.begin()]++;
        cr[std::lower_bound(app.begin(), app.end(), R[i]) - app.begin()]++;
    }
    assert(app[0] == 0LL);
    int ans = cl[0], val = cl[0];
    for (int i = 1 ; i + 1 < (int)app.size() ; i++) {
        val += cl[i] - cr[i];
        ans = std::min(ans, val);
        assert(ans >= 1);
    }
    ans = std::min(N, N - ans + 1);
    return ans;
}
int main() {
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    std::ios::sync_with_stdio(false);
    std::cin >> N >> P;
    for (int i = 0 ; i < N ; i++) std::cin >> L[i] >> R[i];
    std::cout << solveX() << ' ' << solveY() << '\n';
}
accuracy: 1
time_ms: 90
memory_kb: 12460
final_rank: 1

code_snippet: #include <iostream>
#include <iomanip>
#include <cassert>
#include <vector>
#include <algorithm>
#include <utility>
#include <numeric>
#include <tuple>
// #include "Src/Number/IntegerDivision.hpp"
// #include "Src/Utility/BinarySearch.hpp"
// #include "Src/Sequence/CompressedSequence.hpp"
// #include "Src/Sequence/RunLengthEncoding.hpp"
// #include "Src/Algebra/Group/AdditiveGroup.hpp"
// #include "Src/DataStructure/FenwickTree/FenwickTree.hpp"
// using namespace zawa;
// #include "atcoder/modint"
// using mint = atcoder::modint998244353;
#include <queue>
int N;
long long P, L[200020], R[200020];
long long solveX() {
    std::vector<std::pair<long long, long long>> LR(N);
    for (int i = 0 ; i < N ; i++) LR[i] = {L[i], R[i]};
    std::sort(LR.begin(), LR.end());
    int idx = 0;
    std::priority_queue<long long> que;
    while (idx < N and LR[idx].first == 0) {
        que.push(LR[idx].second);
        idx++;
    }
    int ans = 0;
    while (true) {
        assert(que.size());
        ans++;
        long long r = que.top();
        que.pop();
        if (r == P) break;
        while (idx < N and LR[idx].first < r) {
            que.push(LR[idx].second);
            idx++;
        }
    }
    return ans;
}
long long solveY() {
    std::vector<long long> app(N + N);
    for (int i = 0 ; i < N ; i++) {
        app[i] = L[i];
        app[i + N] = R[i];
    }
    std::sort(app.begin(), app.end());
    app.erase(std::unique(app.begin(), app.end()), app.end());
    std::vector<int> cl(app.size()), cr(app.size());
    for (int i = 0 ; i < N ; i++) {
        cl[std::lower_bound(app.begin(), app.end(), L[i]) - app.begin()]++;
        cr[std::lower_bound(app.begin(), app.end(), R[i]) - app.begin()]++;
    }
    assert(app[0] == 0LL);
    int ans = cl[0], val = cl[0];
    for (int i = 1 ; i + 1 < (int)app.size() ; i++) {
        val += cl[i] - cr[i];
        ans = std::min(ans, val);
        assert(ans >= 1);
    }
    ans = std::min(N, N - ans + 1);
    return ans;
}
int main() {
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    std::ios::sync_with_stdio(false);
    std::cin >> N >> P;
    for (int i = 0 ; i < N ; i++) std::cin >> L[i] >> R[i];
    std::cout << solveX() << ' ' << solveY() << '\n';
}
accuracy: 0.34328358208955223
time_ms: 90
memory_kb: 12460
final_rank: 20

code_snippet: #include <iostream>
#include <iomanip>
#include <cassert>
#include <vector>
#include <algorithm>
#include <utility>
#include <numeric>
#include <tuple>
// #include "Src/Number/IntegerDivision.hpp"
// #include "Src/Utility/BinarySearch.hpp"
// #include "Src/Sequence/CompressedSequence.hpp"
// #include "Src/Sequence/RunLengthEncoding.hpp"
// #include "Src/Algebra/Group/AdditiveGroup.hpp"
// #include "Src/DataStructure/FenwickTree/FenwickTree.hpp"
// using namespace zawa;
// #include "atcoder/modint"
// using mint = atcoder::modint998244353;
#include <queue>
int N;
long long P, L[200020], R[200020];
long long solveX() {
    std::vector<std::pair<long long, long long>> LR(N);
    for (int i = 0 ; i < N ; i++) LR[i] = {L[i], R[i]};
    std::sort(LR.begin(), LR.end());
    int idx = 0;
    std::priority_queue<long long> que;
    while (idx < N and LR[idx].first == 0) {
        que.push(LR[idx].second);
        idx++;
    }
    int ans = 0;
    while (true) {
        assert(que.size());
        ans++;
        long long r = que.top();
        que.pop();
        if (r == P) break;
        while (idx < N and LR[idx].first < r) {
            que.push(LR[idx].second);
            idx++;
        }
    }
    return ans;
}
long long solveY() {
    std::sort(L, L + N);
    std::sort(R, R + N);
    int ans = 0, l = 0, r = 0;
    while (l < N and L[l] == 0) {
        ans++;
        l++;
    }
    int val = ans;
    long long prev = 0;
    while (r < N and R[r] < P) {
        long long cur = prev;
        if (l == N) {
            val--;
            cur = R[r++];
        }
        else if (L[l] < R[r]) {
            val++;
            cur = L[l++];
        }
        else {
            val--;
            cur = R[r++];
        }
        if (prev < cur) {
            assert(val >= 1);
            ans = std::min(ans, val);
            prev = cur;
        }
    }
    ans = std::min(N, N - ans + 1);
    return ans;
}
int main() {
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    std::ios::sync_with_stdio(false);
    std::cin >> N >> P;
    for (int i = 0 ; i < N ; i++) std::cin >> L[i] >> R[i];
    std::cout << solveX() << ' ' << solveY() << '\n';
}
accuracy: 0.34328358208955223
time_ms: 50
memory_kb: 11640
final_rank: 18

code_snippet: #include <iostream>
#include <iomanip>
#include <cassert>
#include <vector>
#include <algorithm>
#include <utility>
#include <numeric>
#include <tuple>
// #include "Src/Number/IntegerDivision.hpp"
// #include "Src/Utility/BinarySearch.hpp"
// #include "Src/Sequence/CompressedSequence.hpp"
// #include "Src/Sequence/RunLengthEncoding.hpp"
// #include "Src/Algebra/Group/AdditiveGroup.hpp"
// #include "Src/DataStructure/FenwickTree/FenwickTree.hpp"
// using namespace zawa;
// #include "atcoder/modint"
// using mint = atcoder::modint998244353;
#include <queue>
int N;
long long P, L[200020], R[200020];
long long solveX() {
    std::vector<std::pair<long long, long long>> LR(N);
    for (int i = 0 ; i < N ; i++) LR[i] = {L[i], R[i]};
    std::sort(LR.begin(), LR.end());
    int idx = 0;
    std::priority_queue<long long> que;
    while (idx < N and LR[idx].first == 0) {
        que.push(LR[idx].second);
        idx++;
    }
    int ans = 0;
    while (true) {
        assert(que.size());
        ans++;
        long long r = que.top();
        que.pop();
        if (r == P) break;
        while (idx < N and LR[idx].first < r) {
            que.push(LR[idx].second);
            idx++;
        }
    }
    return ans;
}
long long solveY() {
    std::sort(L, L + N);
    std::sort(R, R + N);
    int ans = 0, l = 0, r = 0;
    while (l < N and L[l] == 0) {
        ans++;
        l++;
    }
    int val = ans;
    long long prev = 0;
    while (r < N and R[r] < P) {
        long long cur = prev;
        if (l == N) {
            val--;
            cur = R[r++];
        }
        else if (L[l] < R[r]) {
            val++;
            cur = L[l++];
        }
        else {
            val--;
            cur = R[r++];
        }
        assert(val >= 1);
        if (prev < cur) {
            ans = std::min(ans, val);
            prev = cur;
        }
    }
    ans = std::min(N, N - ans + 1);
    return ans;
}
int main() {
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    std::ios::sync_with_stdio(false);
    std::cin >> N >> P;
    for (int i = 0 ; i < N ; i++) std::cin >> L[i] >> R[i];
    std::cout << solveX() << ' ' << solveY() << '\n';
}
accuracy: 0.34328358208955223
time_ms: 50
memory_kb: 11640
final_rank: 18

code_snippet: #include <iostream>
#include <algorithm>
#include <vector>
#include <set>

using namespace std;
using ll = long long;

int main() {

	ll n, L;
	cin >> n >> L;
	
	set<ll> s_;
	vector<ll> s;

	vector<pair<ll, ll>> interval;
	for(int i=0;i<n;++i) {
		ll l, r;
		cin >> l >> r;
		interval.push_back({l, r});
		s_.insert(l);
		s_.insert(r);
	}
	
	for(auto v : s_) {
		s.push_back(v);
	}
	
	sort(interval.begin(), interval.end());
	// sort(s.begin(), s.end());
	int size = (int)s.size();
	vector<int> arr(size, 0);

	ll c = 0;
	ll nxt = 0;
	int x = 0;
	for(auto [l, r] : interval) {
		if(c < l) {
			c = nxt;
			x++;
		}
		int idx_l = lower_bound(s.begin(), s.end(), l) - s.begin();
		int idx_r = lower_bound(s.begin(), s.end(), r) - s.begin();
		arr[idx_l]++;
		arr[idx_r]--;
		nxt = max(nxt, r);
	}
	
	if(c != L) x++;
	
	int p = 0;
	int q = n;
	for(auto v : arr) {
		p += v;
		if(!p) break;
		q = min(q, p);
	}
	cout << x << " " << n-q+1 << endl;

	
}
accuracy: 1
time_ms: 260
memory_kb: 30836
final_rank: 14

code_snippet: #include <bits/stdc++.h>

using namespace std;

#define rep(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rrep(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define ALL(v) (v).begin(), (v).end()
#define UNIQUE(v) sort(ALL(v)), (v).erase(unique(ALL(v)), (v).end())
#define SZ(v) (int)v.size()
#define MIN(v) *min_element(ALL(v))
#define MAX(v) *max_element(ALL(v))
#define LB(v, x) int(lower_bound(ALL(v), (x)) - (v).begin())
#define UB(v, x) int(upper_bound(ALL(v), (x)) - (v).begin())

using uint = unsigned int;
using ll = long long int;
using ull = unsigned long long;
using i128 = __int128_t;
using u128 = __uint128_t;
const int inf = 0x3fffffff;
const ll INF = 0x1fffffffffffffff;

template <typename T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T, typename U> T ceil(T x, U y) {
    assert(y != 0);
    if (y < 0)
        x = -x, y = -y;
    return (x > 0 ? (x + y - 1) / y : x / y);
}
template <typename T, typename U> T floor(T x, U y) {
    assert(y != 0);
    if (y < 0)
        x = -x, y = -y;
    return (x > 0 ? x / y : (x - y + 1) / y);
}
template <typename T> int popcnt(T x) {
    return __builtin_popcountll(x);
}
template <typename T> int topbit(T x) {
    return (x == 0 ? -1 : 63 - __builtin_clzll(x));
}
template <typename T> int lowbit(T x) {
    return (x == 0 ? -1 : __builtin_ctzll(x));
}

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << "P(" << p.first << ", " << p.second << ")";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &map_var) {
    os << "{";
    for (auto itr = map_var.begin(); itr != map_var.end(); itr++) {
        os << "(" << itr->first << ", " << itr->second << ")";
        itr++;
        if (itr != map_var.end())
            os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const set<T> &set_var) {
    os << "{";
    for (auto itr = set_var.begin(); itr != set_var.end(); itr++) {
        os << *itr;
        ++itr;
        if (itr != set_var.end())
            os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
#ifdef LOCAL
#define show(...) _show(0, #__VA_ARGS__, __VA_ARGS__)
#else
#define show(...) true
#endif
template <typename T> void _show(int i, T name) {
    cerr << '\n';
}
template <typename T1, typename T2, typename... T3>
void _show(int i, const T1 &a, const T2 &b, const T3 &...c) {
    for (; a[i] != ',' && a[i] != '\0'; i++)
        cerr << a[i];
    cerr << ":" << b << " ";
    _show(i + 1, a, c...);
}

#include <unistd.h>

namespace fastio {
static constexpr uint32_t SZ = 1 << 17;
char ibuf[SZ];
char obuf[SZ];
char out[100];
// pointer of ibuf, obuf


uint32_t pil = 0, pir = 0, por = 0;

struct Pre {
    char num[10000][4];
    constexpr Pre() : num() {
        for (int i = 0; i < 10000; i++) {
            int n = i;
            for (int j = 3; j >= 0; j--) {
                num[i][j] = n % 10 | '0';
                n /= 10;
            }
        }
    }
} constexpr pre;

inline void load() {
    memmove(ibuf, ibuf + pil, pir - pil);
    pir = pir - pil + fread(ibuf + pir - pil, 1, SZ - pir + pil, stdin);
    pil = 0;
    if (pir < SZ)
        ibuf[pir++] = '\n';
}

inline void flush() {
    fwrite(obuf, 1, por, stdout);
    por = 0;
}

void rd(char &c) {
    do {
        if (pil + 1 > pir)
            load();
        c = ibuf[pil++];
    } while (isspace(c));
}

void rd(string &x) {
    x.clear();
    char c;
    do {
        if (pil + 1 > pir)
            load();
        c = ibuf[pil++];
    } while (isspace(c));
    do {
        x += c;
        if (pil == pir)
            load();
        c = ibuf[pil++];
    } while (!isspace(c));
}

template <typename T> void rd_real(T &x) {
    string s;
    rd(s);
    x = stod(s);
}

template <typename T> void rd_integer(T &x) {
    if (pil + 100 > pir)
        load();
    char c;
    do
        c = ibuf[pil++];
    while (c < '-');
    bool minus = 0;
    if constexpr (is_signed<T>::value || is_same_v<T, i128>) {
        if (c == '-') {
            minus = 1, c = ibuf[pil++];
        }
    }
    x = 0;
    while ('0' <= c) {
        x = x * 10 + (c & 15), c = ibuf[pil++];
    }
    if constexpr (is_signed<T>::value || is_same_v<T, i128>) {
        if (minus)
            x = -x;
    }
}

void rd(int &x) {
    rd_integer(x);
}
void rd(ll &x) {
    rd_integer(x);
}
void rd(i128 &x) {
    rd_integer(x);
}
void rd(uint &x) {
    rd_integer(x);
}
void rd(ull &x) {
    rd_integer(x);
}
void rd(u128 &x) {
    rd_integer(x);
}
void rd(double &x) {
    rd_real(x);
}
void rd(long double &x) {
    rd_real(x);
}

template <class T, class U> void rd(pair<T, U> &p) {
    return rd(p.first), rd(p.second);
}
template <size_t N = 0, typename T> void rd_tuple(T &t) {
    if constexpr (N < std::tuple_size<T>::value) {
        auto &x = std::get<N>(t);
        rd(x);
        rd_tuple<N + 1>(t);
    }
}
template <class... T> void rd(tuple<T...> &tpl) {
    rd_tuple(tpl);
}

template <size_t N = 0, typename T> void rd(array<T, N> &x) {
    for (auto &d : x)
        rd(d);
}
template <class T> void rd(vector<T> &x) {
    for (auto &d : x)
        rd(d);
}

void read() {}
template <class H, class... T> void read(H &h, T &...t) {
    rd(h), read(t...);
}

void wt(const char c) {
    if (por == SZ)
        flush();
    obuf[por++] = c;
}
void wt(const string s) {
    for (char c : s)
        wt(c);
}
void wt(const char *s) {
    size_t len = strlen(s);
    for (size_t i = 0; i < len; i++)
        wt(s[i]);
}

template <typename T> void wt_integer(T x) {
    if (por > SZ - 100)
        flush();
    if (x < 0) {
        obuf[por++] = '-', x = -x;
    }
    int outi;
    for (outi = 96; x >= 10000; outi -= 4) {
        memcpy(out + outi, pre.num[x % 10000], 4);
        x /= 10000;
    }
    if (x >= 1000) {
        memcpy(obuf + por, pre.num[x], 4);
        por += 4;
    } else if (x >= 100) {
        memcpy(obuf + por, pre.num[x] + 1, 3);
        por += 3;
    } else if (x >= 10) {
        int q = (x * 103) >> 10;
        obuf[por] = q | '0';
        obuf[por + 1] = (x - q * 10) | '0';
        por += 2;
    } else
        obuf[por++] = x | '0';
    memcpy(obuf + por, out + outi + 4, 96 - outi);
    por += 96 - outi;
}

template <typename T> void wt_real(T x) {
    ostringstream oss;
    oss << fixed << setprecision(15) << double(x);
    string s = oss.str();
    wt(s);
}

void wt(int x) {
    wt_integer(x);
}
void wt(ll x) {
    wt_integer(x);
}
void wt(i128 x) {
    wt_integer(x);
}
void wt(uint x) {
    wt_integer(x);
}
void wt(ull x) {
    wt_integer(x);
}
void wt(u128 x) {
    wt_integer(x);
}
void wt(double x) {
    wt_real(x);
}
void wt(long double x) {
    wt_real(x);
}

template <class T, class U> void wt(const pair<T, U> val) {
    wt(val.first);
    wt(' ');
    wt(val.second);
}
template <size_t N = 0, typename T> void wt_tuple(const T t) {
    if constexpr (N < std::tuple_size<T>::value) {
        if constexpr (N > 0) {
            wt(' ');
        }
        const auto x = std::get<N>(t);
        wt(x);
        wt_tuple<N + 1>(t);
    }
}
template <class... T> void wt(tuple<T...> tpl) {
    wt_tuple(tpl);
}
template <class T, size_t S> void wt(const array<T, S> val) {
    auto n = val.size();
    for (size_t i = 0; i < n; i++) {
        if (i)
            wt(' ');
        wt(val[i]);
    }
}
template <class T> void wt(const vector<T> val) {
    auto n = val.size();
    for (size_t i = 0; i < n; i++) {
        if (i)
            wt(' ');
        wt(val[i]);
    }
}

void print() {
    wt('\n');
}
template <class Head, class... Tail> void print(Head &&head, Tail &&...tail) {
    wt(head);
    if (sizeof...(Tail))
        wt(' ');
    print(forward<Tail>(tail)...);
}
void __attribute__((destructor)) _d() {
    flush();
}
} // namespace fastio


using fastio::flush;
using fastio::print;
using fastio::read;

inline void first(bool i = true) {
    print(i ? "first" : "second");
}
inline void Alice(bool i = true) {
    print(i ? "Alice" : "Bob");
}
inline void Takahashi(bool i = true) {
    print(i ? "Takahashi" : "Aoki");
}
inline void yes(bool i = true) {
    print(i ? "yes" : "no");
}
inline void Yes(bool i = true) {
    print(i ? "Yes" : "No");
}
inline void No() {
    print("No");
}
inline void YES(bool i = true) {
    print(i ? "YES" : "NO");
}
inline void NO() {
    print("NO");
}
inline void Yay(bool i = true) {
    print(i ? "Yay!" : ":(");
}
inline void Possible(bool i = true) {
    print(i ? "Possible" : "Impossible");
}
inline void POSSIBLE(bool i = true) {
    print(i ? "POSSIBLE" : "IMPOSSIBLE");
}

/**
 * @brief Fast IO
 */

int main() {
    int N;
    ll M;
    cin >> N >> M;
    vector<ll> L(N), R(N), X;
    X.push_back(0), X.push_back(M);
    rep(i,0,N) {
        cin >> L[i] >> R[i];
        X.push_back(L[i]);
        X.push_back(R[i]);
    }
    UNIQUE(X);
    M = LB(X,M)+1;
    rep(i,0,N) {
        L[i] = LB(X,L[i]);
        R[i] = LB(X,R[i]);
    }
    vector<vector<int>> G(M);
    rep(i,0,N) G[L[i]].push_back(R[i]);
    vector<int> Dist(M,inf);
    Dist[0] = 0;
    priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> PQ;
    PQ.push({0,0});
    while(!PQ.empty()) {
        auto [D,P] = PQ.top();
        PQ.pop();
        if (Dist[P] < D) continue;
        if (P > 0) {
            if (chmin(Dist[P-1],D)) {
                PQ.push({D,P-1});
            }
        }
        for (int NP : G[P]) {
            if (chmin(Dist[NP],D+1)) {
                PQ.push({D+1,NP});
            }
        }
    }
    cout << Dist[M-1] << ' ';
    vector<int> S(M,0);
    rep(i,0,N) {
        S[L[i]]++,S[R[i]]--;
    }
    rep(i,0,M-1) S[i+1] += S[i];
    int ANS = inf;
    rep(i,0,M-1) chmin(ANS,S[i]);
    cout << N-ANS+1 << endl;
}
accuracy: 1
time_ms: 220
memory_kb: 28788
final_rank: 10

code_snippet: #include<bits/stdc++.h>
using namespace std;
using ll=long long;
int main() {
    ll N,L;
    cin>>N>>L;
    vector<pair<ll,ll>> P(N);
    map<ll,ll> M;
    for(int i=0;i<N;i++){
        cin>>P[i].first>>P[i].second;
        M[P[i].first]++;
        M[P[i].second+1]--;
    }
    ll bn=0,cnt=0,x=0,an=0,MX=0;
    for(auto [m,a]:M){
        cnt+=a;
        if(m<=L)bn=max(bn,N-cnt+1);
    }
    sort(P.begin(),P.end());
    for(int i=0;i<N;i++){
        if(x<P[i].first){
            an++;
            x=MX;
        }
        MX=max(MX,P[i].second);
    }
    if(x<L)an++;
    cout<<an<<" "<<bn<<endl;
}
accuracy: 1
time_ms: 260
memory_kb: 30020
final_rank: 11

code_snippet: #include<bits/stdc++.h>
using namespace std;
using ll=long long;

int main() {cin.tie(nullptr);
    ios::sync_with_stdio(false);

    ll N,L;
    cin>>N>>L;
    vector<pair<ll,ll>> P(N);
    map<ll,ll> M;
    for(int i=0;i<N;i++){
        cin>>P[i].first>>P[i].second;
        M[P[i].first]++;
        M[P[i].second+1]--;
    }
    ll bn=N+1,cnt=0,x=0,an=0,MX=0;
    for(auto m:M){
        cnt+=m.second;
        if(m.first<=L)bn=min(bn,cnt);
    }
    sort(P.begin(),P.end());
    for(int i=0;i<N;i++){
        if(x<P[i].first){
            an++;
            x=MX;
        }
        MX=max(MX,P[i].second);
    }
    if(x<L)an++;
    cout<<an<<" "<<N-bn+1<<endl;
}
accuracy: 1
time_ms: 180
memory_kb: 30156
final_rank: 7

code_snippet: #include<bits/stdc++.h>
using namespace std;
using ll=long long;

int main() {
    ll N,L;
    cin>>N>>L;
    vector<pair<ll,ll>> P(N);
    map<ll,ll> M;
    for(int i=0;i<N;i++){
        cin>>P[i].first>>P[i].second;
        M[P[i].first]++;
        M[P[i].second+1]--;
    }
    ll bn=N+1,cnt=0,x=0,an=0,MX=0;
    for(auto m:M){
        cnt+=m.second;
        if(m.first<=L)bn=min(bn,cnt);
    }
    sort(P.begin(),P.end());
    for(int i=0;i<N;i++){
        if(x<P[i].first){
            an++;
            x=MX;
        }
        MX=max(MX,P[i].second);
    }
    if(x<L)an++;
    cout<<an<<" "<<N-bn+1<<endl;
}
accuracy: 1
time_ms: 260
memory_kb: 30040
final_rank: 12

code_snippet: // competitive-verifier: PROBLEM
#include <algorithm>
#include <iterator>
#include <vector>
/**
 * @brief 座標圧縮
 *
 * @tparam T 要素の型
 */
template <class T>
struct coordinate_compression {
    coordinate_compression() = default;
    coordinate_compression(const std::vector<T> &_data) : data(_data) { build(); }
    const T &operator[](int i) const { return data[i]; }
    T &operator[](int i) { return data[i]; }
    void add(T x) { data.emplace_back(x); }
    void build() {
        std::sort(std::begin(data), std::end(data));
        data.erase(std::unique(std::begin(data), std::end(data)), std::end(data));
    }
    bool exists(T x) const {
        auto it = std::lower_bound(std::begin(data), std::end(data), x);
        return it != std::end(data) && *it == x;
    }
    int get(T x) const {
        auto it = std::lower_bound(std::begin(data), std::end(data), x);
        return std::distance(std::begin(data), it);
    }
    int size() const { return std::size(data); }
  private:
    std::vector<T> data;
};
/**
 * @brief 座標圧縮
 *
 * @tparam T 要素の型
 * @param v 配列
 * @return std::vector<T>
 */
template <class T>
std::vector<T> compress(const std::vector<T> &v) {
    coordinate_compression cps(v);
    std::vector<T> res;
    res.reserve(std::size(v));
    for (auto &&x : v) res.emplace_back(cps.get(x));
    return res;
}
#include <cassert>
namespace internal {
// @return same with std::bit::bit_ceil
unsigned int bit_ceil(unsigned int n) {
    unsigned int x = 1;
    while (x < (unsigned int)(n)) x *= 2;
    return x;
}
// @param n `1 <= n`
// @return same with std::bit::countl_zero
int countl_zero(unsigned int n) { return __builtin_clz(n); }
// @param n `1 <= n`
// @return same with std::bit::countr_zero
int countr_zero(unsigned int n) { return __builtin_ctz(n); }
// @param n `1 <= n`
// @return same with std::bit::countr_zero
constexpr int countr_zero_constexpr(unsigned int n) {
    int x = 0;
    while (!(n & (1 << x))) x++;
    return x;
}
}  // namespace internal
#include <limits>
#include <utility>
template <class T>
struct Add {
    using value_type = T;
    static constexpr T id() { return T(); }
    static constexpr T op(const T &lhs, const T &rhs) { return lhs + rhs; }
    template <class U>
    static constexpr U f(T lhs, U rhs) {
        return lhs + rhs;
    }
};
template <class T>
struct Mul {
    using value_type = T;
    static constexpr T id() { return T(1); }
    static constexpr T op(const T &lhs, const T &rhs) { return lhs * rhs; }
    template <class U>
    static constexpr U f(T lhs, U rhs) {
        return lhs * rhs;
    }
};
template <class T>
struct And {
    using value_type = T;
    static constexpr T id() { return std::numeric_limits<T>::max(); }
    static constexpr T op(const T &lhs, const T &rhs) { return lhs & rhs; }
    template <class U>
    static constexpr U f(T lhs, U rhs) {
        return lhs & rhs;
    }
};
template <class T>
struct Or {
    using value_type = T;
    static constexpr T id() { return T(); }
    static constexpr T op(const T &lhs, const T &rhs) { return lhs | rhs; }
    template <class U>
    static constexpr U f(T lhs, U rhs) {
        return lhs | rhs;
    }
};
template <class T>
struct Xor {
    using value_type = T;
    static constexpr T id() { return T(); }
    static constexpr T op(const T &lhs, const T &rhs) { return lhs ^ rhs; }
    template <class U>
    static constexpr U f(T lhs, U rhs) {
        return lhs ^ rhs;
    }
};
template <class T>
struct Min {
    using value_type = T;
    static constexpr T id() { return std::numeric_limits<T>::max(); }
    static constexpr T op(const T &lhs, const T &rhs) { return std::min(lhs, rhs); }
    template <class U>
    static constexpr U f(T lhs, U rhs) {
        return std::min((U)lhs, rhs);
    }
};
template <class T>
struct Max {
    using value_type = T;
    static constexpr T id() { return std::numeric_limits<T>::lowest(); }
    static constexpr T op(const T &lhs, const T &rhs) { return std::max(lhs, rhs); }
    template <class U>
    static constexpr U f(T lhs, U rhs) {
        return std::max((U)lhs, rhs);
    }
};
template <class T>
struct Update {
    using value_type = T;
    static constexpr T id() { return std::numeric_limits<T>::max(); }
    static constexpr T op(const T &lhs, const T &rhs) { return lhs == Update::id() ? rhs : lhs; }
    template <class U>
    static constexpr U f(T lhs, U rhs) {
        return lhs == Update::id() ? rhs : lhs;
    }
};
template <class T>
struct Affine {
    using P = std::pair<T, T>;
    using value_type = P;
    static constexpr P id() { return P(1, 0); }
    static constexpr P op(P lhs, P rhs) {
        return {lhs.first * rhs.first, lhs.first * rhs.second + lhs.second};
    }
};
template <class M>
struct Rev {
    using T = typename M::value_type;
    using value_type = T;
    static constexpr T id() { return M::id(); }
    static constexpr T op(T lhs, T rhs) { return M::op(rhs, lhs); }
};
/**
 * @brief 遅延評価セグメント木
 * @see https://github.com/atcoder/ac-library/blob/master/atcoder/lazysegtree.hpp
 *
 * @tparam S モノイド
 * @tparam F モノイド
 */
template <class S, class F>
struct lazy_segment_tree {
  private:
    using T = typename S::value_type;
    using U = typename F::value_type;
  public:
    lazy_segment_tree() : lazy_segment_tree(0) {}
    explicit lazy_segment_tree(int n, T e = S::id()) : lazy_segment_tree(std::vector<T>(n, e)) {}
    explicit lazy_segment_tree(const std::vector<T> &v) : _n(int(v.size())) {
        _size = internal::bit_ceil(_n);
        _log = internal::countr_zero(_size);
        data = std::vector<T>(2 * _size, S::id());
        lazy = std::vector<U>(_size, F::id());
        for (int i = 0; i < _n; i++) data[_size + i] = v[i];
        for (int i = _size - 1; i >= 1; --i) update(i);
    }
    void set(int p, T x) {
        assert(0 <= p && p < _n);
        p += _size;
        for (int i = _log; i >= 1; --i) push(p >> i);
        data[p] = x;
        for (int i = 1; i <= _log; ++i) update(p >> i);
    }
    T at(int p) { return get(p); }
    T get(int p) {
        assert(0 <= p && p < _n);
        p += _size;
        for (int i = _log; i >= 1; --i) push(p >> i);
        return data[p];
    }
    void apply(int p, U f) {
        assert(0 <= p && p < _n);
        p += _size;
        for (int i = _log; i >= 1; --i) push(p >> i);
        data[p] = F::f(f, data[p]);
        for (int i = 1; i <= _log; ++i) update(p >> i);
    }
    void apply(int l, int r, U f) {
        assert(0 <= l && l <= r && r <= _n);
        if (l == r) return;
        l += _size, r += _size;
        for (int i = _log; i >= 1; --i) {
            if (((l >> i) << i) != l) push(l >> i);
            if (((r >> i) << i) != r) push((r - 1) >> i);
        }
        int l2 = l, r2 = r;
        while (l < r) {
            if (l & 1) all_apply(l++, f);
            if (r & 1) all_apply(--r, f);
            l >>= 1, r >>= 1;
        }
        l = l2, r = r2;
        for (int i = 1; i <= _log; i++) {
            if (((l >> i) << i) != l) update(l >> i);
            if (((r >> i) << i) != r) update((r - 1) >> i);
        }
    }
    T prod(int l, int r) {
        assert(0 <= l && l <= r && r <= _n);
        if (l == r) return S::id();
        l += _size, r += _size;
        for (int i = _log; i >= 1; --i) {
            if (((l >> i) << i) != l) push(l >> i);
            if (((r >> i) << i) != r) push((r - 1) >> i);
        }
        T sml = S::id(), smr = S::id();
        while (l < r) {
            if (l & 1) sml = S::op(sml, data[l++]);
            if (r & 1) smr = S::op(data[--r], smr);
            l >>= 1, r >>= 1;
        }
        return S::op(sml, smr);
    }
    T all_prod() const { return data[1]; }
  private:
    int _n, _size, _log;
    std::vector<T> data;
    std::vector<U> lazy;
    void update(int k) { data[k] = S::op(data[2 * k], data[2 * k + 1]); }
    void all_apply(int k, U f) {
        data[k] = F::f(f, data[k]);
        if (k < _size) lazy[k] = F::op(f, lazy[k]);
    }
    void push(int k) {
        all_apply(2 * k, lazy[k]);
        all_apply(2 * k + 1, lazy[k]);
        lazy[k] = F::id();
    }
};
/**
 * @brief セグメント木
 * @see https://noshi91.hatenablog.com/entry/2020/04/22/212649
 *
 * @tparam M モノイド
 */
template <class M>
struct segment_tree {
  private:
    using T = typename M::value_type;
    struct _segment_tree_reference {
      private:
        segment_tree<M> &self;
        int k;
      public:
        _segment_tree_reference(segment_tree<M> &self, int k) : self(self), k(k) {}
        _segment_tree_reference &operator=(const T &x) {
            self.set(k, x);
            return *this;
        }
        _segment_tree_reference &operator=(T &&x) {
            self.set(k, std::move(x));
            return *this;
        }
        operator T() const { return self.get(k); }
    };
  public:
    segment_tree() : segment_tree(0) {}
    explicit segment_tree(int n, T e = M::id()) : segment_tree(std::vector<T>(n, e)) {}
    template <class U>
    explicit segment_tree(const std::vector<U> &v) : _n(v.size()) {
        _size = internal::bit_ceil(_n);
        _log = internal::countr_zero(_size);
        data = std::vector<T>(_size << 1, M::id());
        for (int i = 0; i < _n; ++i) data[_size + i] = T(v[i]);
        for (int i = _size - 1; i >= 1; --i) update(i);
    }
    const T &operator[](int k) const { return data[k + _size]; }
    _segment_tree_reference operator[](int k) { return _segment_tree_reference(*this, k); }
    T at(int k) const { return data[k + _size]; }
    T get(int k) const { return data[k + _size]; }
    void set(int k, T val) {
        assert(0 <= k && k < _n);
        k += _size;
        data[k] = val;
        for (int i = 1; i <= _log; ++i) update(k >> i);
    }
    void reset(int k) { set(k, M::id()); }
    T all_prod() const { return data[1]; }
    T prod(int a, int b) const {
        assert(0 <= a && b <= _n);
        T l = M::id(), r = M::id();
        for (a += _size, b += _size; a < b; a >>= 1, b >>= 1) {
            if (a & 1) l = M::op(l, data[a++]);
            if (b & 1) r = M::op(data[--b], r);
        }
        return M::op(l, r);
    }
    template <class F>
    int max_right(F f) const {
        return max_right(0, f);
    }
    template <class F>
    int max_right(int l, F f) const {
        assert(0 <= l && l <= _n);
        assert(f(M::id()));
        if (l == _n) return _n;
        l += _size;
        T sm = M::id();
        do {
            while (l % 2 == 0) l >>= 1;
            if (!f(M::op(sm, data[l]))) {
                while (l < _size) {
                    l = (2 * l);
                    if (f(M::op(sm, data[l]))) {
                        sm = M::op(sm, data[l]);
                        l++;
                    }
                }
                return l - _size;
            }
            sm = M::op(sm, data[l]);
            l++;
        } while ((l & -l) != l);
        return _n;
    }
    template <class F>
    int min_left(F f) const {
        return min_left(_n, f);
    }
    template <class F>
    int min_left(int r, F f) const {
        assert(0 <= r && r <= _n);
        assert(f(M::id()));
        if (r == 0) return 0;
        r += _size;
        T sm = M::id();
        do {
            r--;
            while (r > 1 && (r % 2)) r >>= 1;
            if (!f(M::op(data[r], sm))) {
                while (r < _size) {
                    r = (2 * r + 1);
                    if (f(M::op(data[r], sm))) {
                        sm = M::op(data[r], sm);
                        r--;
                    }
                }
                return r + 1 - _size;
            }
            sm = M::op(data[r], sm);
        } while ((r & -r) != r);
        return 0;
    }
  private:
    int _n, _size, _log;
    std::vector<T> data;
    void update(int k) { data[k] = M::op(data[2 * k], data[2 * k + 1]); }
};
#ifdef ATCODER
#pragma GCC target("sse4.2,avx512f,avx512dq,avx512ifma,avx512cd,avx512bw,avx512vl,bmi2")
#endif
#pragma GCC optimize("Ofast,fast-math,unroll-all-loops")
#include <bits/stdc++.h>
#ifndef ATCODER
#pragma GCC target("sse4.2,avx2,bmi2")
#endif
template <class T, class U>
constexpr bool chmax(T &a, const U &b) {
    return a < (T)b ? a = (T)b, true : false;
}
template <class T, class U>
constexpr bool chmin(T &a, const U &b) {
    return (T)b < a ? a = (T)b, true : false;
}
constexpr std::int64_t INF = 1000000000000000003;
constexpr int Inf = 1000000003;
constexpr double EPS = 1e-7;
constexpr double PI = 3.14159265358979323846;
#define FOR(i, m, n) for (int i = (m); i < int(n); ++i)
#define FORR(i, m, n) for (int i = (m)-1; i >= int(n); --i)
#define FORL(i, m, n) for (int64_t i = (m); i < int64_t(n); ++i)
#define rep(i, n) FOR (i, 0, n)
#define repn(i, n) FOR (i, 1, n + 1)
#define repr(i, n) FORR (i, n, 0)
#define repnr(i, n) FORR (i, n + 1, 1)
#define all(s) (s).begin(), (s).end()
struct Sonic {
    Sonic() {
        std::ios::sync_with_stdio(false);
        std::cin.tie(nullptr);
        std::cout << std::fixed << std::setprecision(20);
    }
    constexpr void operator()() const {}
} sonic;
using namespace std;
using ll = std::int64_t;
using ld = long double;
template <class T, class U>
std::istream &operator>>(std::istream &is, std::pair<T, U> &p) {
    return is >> p.first >> p.second;
}
template <class T>
std::istream &operator>>(std::istream &is, std::vector<T> &v) {
    for (T &i : v) is >> i;
    return is;
}
template <class T, class U>
std::ostream &operator<<(std::ostream &os, const std::pair<T, U> &p) {
    return os << '(' << p.first << ',' << p.second << ')';
}
template <class T>
std::ostream &operator<<(std::ostream &os, const std::vector<T> &v) {
    for (auto it = v.begin(); it != v.end(); ++it) os << (it == v.begin() ? "" : " ") << *it;
    return os;
}
template <class Head, class... Tail>
void co(Head &&head, Tail &&...tail) {
    if constexpr (sizeof...(tail) == 0) std::cout << head << '\n';
    else std::cout << head << ' ', co(std::forward<Tail>(tail)...);
}
template <class Head, class... Tail>
void ce(Head &&head, Tail &&...tail) {
    if constexpr (sizeof...(tail) == 0) std::cerr << head << '\n';
    else std::cerr << head << ' ', ce(std::forward<Tail>(tail)...);
}
void Yes(bool is_correct = true) { std::cout << (is_correct ? "Yes\n" : "No\n"); }
void No(bool is_not_correct = true) { Yes(!is_not_correct); }
void YES(bool is_correct = true) { std::cout << (is_correct ? "YES\n" : "NO\n"); }
void NO(bool is_not_correct = true) { YES(!is_not_correct); }
void Takahashi(bool is_correct = true) { std::cout << (is_correct ? "Takahashi" : "Aoki") << '\n'; }
void Aoki(bool is_not_correct = true) { Takahashi(!is_not_correct); }
int main(void) {
    ll n, l;
    cin >> n >> l;
    vector<pair<ll, ll>> a(n);
    cin >> a;
    coordinate_compression<ll> cps;
    rep (i, n) {
        cps.add(a[i].first);
        cps.add(a[i].second);
    }
    cps.build();
    rep (i, n) {
        a[i].first = cps.get(a[i].first);
        a[i].second = cps.get(a[i].second);
    }
    sort(all(a), [](auto x, auto y) {
        if (x.second == y.second)
            return x.first > y.first;
        return x.second < y.second;
    });
    segment_tree<Min<ll>> st(cps.size());
    st.set(0, 0);
    for (auto [x, y] : a) {
        if (st.prod(x, y + 1) != Min<ll>::id())
            st.set(y, st.prod(x, y + 1) + 1);
    }
    ll ansX = st.get(cps.size() - 1);
    lazy_segment_tree<Min<ll>, Add<ll>> lst(cps.size());
    rep (i, cps.size()) lst.set(i, 0);
    for (auto [x, y] : a) {
        lst.apply(x, y, 1);
    }
    ll ansY = lst.prod(0, cps.size() - 1);
    co(ansX, n - ansY + 1);
    return 0;
}
accuracy: 1
time_ms: 170
memory_kb: 32852
final_rank: 9

code_snippet: #include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define db double
#define pii pair<int,int>
#define pli pair<ll,int>
#define pil pair<int,ll>
#define pll pair<ll,ll>
#define ti3 tuple<int,int,int>
#define int128 __int128_t
#define pii128 pair<int128,int128>
const int inf = 1 << 30;
const ll linf = (ll)4e18 + 10;;
const db EPS = 1e-10;
const db pi = acos(-1);
template<class T> bool chmin(T& x, T y){
    if(x > y) {
        x = y;
        return true;
    } else return false;
}
template<class T> bool chmax(T& x, T y){
    if(x < y) {
        x = y;
        return true;
    } else return false;
}

// overload macro
#define CAT( A, B ) A ## B
#define SELECT( NAME, NUM ) CAT( NAME, NUM )

#define GET_COUNT( _1, _2, _3, _4, _5, _6 /* ad nauseam */, COUNT, ... ) COUNT
#define VA_SIZE( ... ) GET_COUNT( __VA_ARGS__, 6, 5, 4, 3, 2, 1 )

#define VA_SELECT( NAME, ... ) SELECT( NAME, VA_SIZE(__VA_ARGS__) )(__VA_ARGS__)

// rep(overload)
#define rep( ... ) VA_SELECT(rep, __VA_ARGS__)
#define rep2(i, n) for (int i = 0; i < int(n); i++)
#define rep3(i, a, b) for (int i = a; i < int(b); i++)
#define rep4(i, a, b, c) for (int i = a; i < int(b); i += c)

// repll(overload)
#define repll( ... ) VA_SELECT(repll, __VA_ARGS__)
#define repll2(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repll3(i, a, b) for (ll i = a; i < (ll)(b); i++)
#define repll4(i, a, b, c) for (ll i = a; i < (ll)(b); i += c)

// rrep(overload)
#define rrep( ... ) VA_SELECT(rrep, __VA_ARGS__)
#define rrep2(i, n) for (int i = n - 1; i >= 0; i--)
#define rrep3(i, a, b) for (int i = (b) - 1; i >= a; i--)
#define rrep4(i, a, b, c) for (int i = (b) - 1; i >= a; i -= c)

// rrepll(overload)
#define rrepll( ... ) VA_SELECT(rrepll, __VA_ARGS__)
#define rrepll2(i, n) for (ll i = (ll)(n) - 1; i >= 0ll; i--)
#define rrepll3(i, a, b) for (ll i = (b) - 1; i >= (ll)(a); i--)
#define rrepll4(i, a, b, c) for (ll i = (b) - 1; i >= (ll)(a); i -= c)

// for_earh
#define fore(e, v) for (auto&& e : v)

// vector
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

int N;
ll L;
ll l[400010], r[400010];
int mxr[400010];
int cntl[400010], cntr[400010];
vector<int> rs[400010];
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    cin >> N >> L;
    vector<ll> lrs;
    rep (i, N) {
        cin >> l[i] >> r[i];
        lrs.push_back(l[i]);
        lrs.push_back(r[i]);
    }
    sort(all(lrs));
    lrs.erase(unique(all(lrs)), lrs.end());
    rep (i, N) {
        l[i] = lower_bound(all(lrs), l[i]) - lrs.begin();
        r[i] = lower_bound(all(lrs), r[i]) - lrs.begin();
        cntl[l[i]]++;
        cntr[r[i]]++;
        rs[l[i]].push_back(r[i]);
        chmax(mxr[l[i]], (int)r[i]);
    }
    priority_queue<pii, vector<pii>, greater<pii>> pq;
    pq.push({0, 0});
    // xを求める
    int x = inf;
    rep (i, lrs.size()) {
        while (!pq.empty()) {
            auto [val, lim] = pq.top();
            if (lim < i) pq.pop();
            else break;
        }
        if (mxr[i] == 0) continue;
        int nval = pq.top().first + 1;
        pq.push({nval, mxr[i]});
    }
    x = pq.top().first;
    // yを求める
    int y = 0, cnt = 0;
    rep (i, lrs.size() - 1) {
        cnt += cntl[i] - cntr[i];
        chmax(y, N - cnt + 1);
    }
    cout << x << ' ' << y << endl;
}
accuracy: 1
time_ms: 110
memory_kb: 34300
final_rank: 6

code_snippet: #line 2 "cp-library/src/cp-template.hpp"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull  = unsigned long long;
using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;
using i128 = __int128_t;
template < class T > bool chmin(T& a, T b) { if(a > b) { a = b; return true; } return false; }
template < class T > bool chmax(T& a, T b) { if(a < b) { a = b; return true; } return false; }
template < class T, class U > T ceil (T x, U y) { return (x > 0 ? (x + y - 1) / y :           x / y); }
template < class T, class U > T floor(T x, U y) { return (x > 0 ?           x / y : (x - y + 1) / y); }
int popcnt(i32 x) { return __builtin_popcount(x); }
int popcnt(u32 x) { return __builtin_popcount(x); }
int popcnt(i64 x) { return __builtin_popcountll(x); }
int popcnt(u64 x) { return __builtin_popcountll(x); }

#line 2 "cp-library/src/utility/rep_itr.hpp"
template < class T > struct itr_rep {
    T i, d;
    constexpr itr_rep(const T i) noexcept : i(i), d(1) {}
    constexpr itr_rep(const T i, const T d) noexcept : i(i), d(d) {}
    void operator++() noexcept { i += d; }
    constexpr int operator*() const noexcept { return i; }
    constexpr bool operator!=(const itr_rep x) const noexcept { return d > 0 ? i < x.i : i > x.i; }
};

template < class T > struct rep {
    const itr_rep< T > s, t;
    constexpr rep(const T t) noexcept : s(0), t(t) {}
    constexpr rep(const T s, const T t) noexcept : s(s), t(t) {}
    constexpr rep(const T s, const T t, const T d) noexcept : s(s, d), t(t, d) {}
    constexpr auto begin() const noexcept { return s; }
    constexpr auto end  () const noexcept { return t; }
};

template < class T > struct revrep {
    const itr_rep < T > s, t;
    constexpr revrep(const T t) noexcept : s(t - 1, -1), t(-1, -1) {}
    constexpr revrep(const T s, const T t) noexcept : s(t - 1, -1), t(s - 1, -1) {}
    constexpr revrep(const T s, const T t, const T d) noexcept : s(t - 1, -d), t(s - 1, -d) {}
    constexpr auto begin() const noexcept { return s; }
    constexpr auto end  () const noexcept { return t; }
};
#line 3 "cp-library/src/utility/io.hpp"

/* 128bit integer */
istream& operator>>(istream& is, i128& x) {
    std::string s; is >> s;
    int pm = (s[0] == '-');
    x = 0;
    for(int i : rep(pm, int(s.size()))) x = x * 10 + (s[i] - '0');
    if(pm) x *= -1;
    return is;
}
ostream& operator<<(ostream& os, const i128& x) {
    if(x == 0) return os << '0';
    i128 y = x;
    if(y < 0) { os << '-'; y *= -1; }
    std::vector<int> ny;
    while(y > 0) { ny.push_back(y % 10); y /= 10; }
    for(int i : revrep(ny.size())) os << ny[i];
    return os;
}

template < class S, class T > istream& operator>>(istream& is,       std::pair< S, T >& x) { is >> x.first        >> x.second; return is; }
template < class S, class T > ostream& operator<<(ostream& os, const std::pair< S, T >& x) { os << x.first << " " << x.second; return os; }

namespace scanner {
    struct sca {
        template < class T > operator T() {
            T s; std::cin >> s; return s;
        }
    };
    struct vec {
        int n;
        vec(int n) : n(n) {}
        template < class T > operator std::vector< T >() {
            std::vector< T > v(n);
            for(T& x : v) std::cin >> x;
            return v;
        }
    };
    struct mat {
        int h, w;
        mat(int h, int w) : h(h), w(w) {}
        template < class T > operator std::vector< std::vector< T > >() {
            std::vector m(h, std::vector< T >(w));
            for(std::vector< T >& v : m) for(T& x : v) std::cin >> x;
            return m;
        }
    };
    struct speedup {
        speedup() {
            std::cin.tie(0);
            std::ios::sync_with_stdio(0);
        }
    } speedup_instance;
}
scanner::sca in() { return scanner::sca(); }
scanner::vec in(int n) { return scanner::vec(n); }
scanner::mat in(int h, int w) { return scanner::mat(h, w); }

namespace printer {
    void precision(int d) { std::cout << std::fixed << std::setprecision(d); }
    void flush() { std::cout.flush(); }
}

template < class T >
ostream& operator<<(ostream& os, const std::vector< T > a) {
    int n = a.size();
    for(int i : rep(n)) { os << a[i]; if(i != n - 1) os << ' '; }
    return os;
}

int print() { std::cout << '\n'; return 0; }
template < class head, class... tail > int print(head&& h, tail&&... t) {
    std::cout << h; if(sizeof...(tail)) std::cout << ' ';
    return print(std::forward<tail>(t)...);
}
template < class T > int print_n(const std::vector< T > a) {
    int n = a.size();
    for(int i : rep(n)) std::cout << a[i] << "\n";
    return 0;
}


#line 2 "cp-library/src/utility/key_val.hpp"

template < class K, class V >
struct key_val {
    K key; V val;
    key_val() {}
    key_val(K key, V val) : key(key), val(val) {}
    template < std::size_t Index >
    std::tuple_element_t< Index, key_val >& get() {
        if constexpr (Index == 0) return key;
        if constexpr (Index == 1) return val;
    }
};

namespace std {

template < class K, class V > struct tuple_size < key_val< K, V > > : integral_constant< size_t, 2 > {};
template < class K, class V > struct tuple_element < 0, key_val< K, V > > { using type = K; };
template < class K, class V > struct tuple_element < 1, key_val< K, V > > { using type = V; };

}
#line 2 "cp-library/src/utility/vec_op.hpp"
template < class T > key_val< int, T > max_of(const vector< T >& a) {
    int i = std::max_element(a.begin(), a.end()) - a.begin();
    return {i, a[i]};
}
template < class T > key_val< int, T > min_of(const vector< T >& a) {
    int i = std::min_element(a.begin(), a.end()) - a.begin();
    return {i, a[i]};
}
template < class S, class T > S sum_of(const vector< T >& a) {
    S sum = 0;
    for(const T x : a) sum += x;
    return sum;
}
template < class S, class T > vector< S > freq_of(const vector< T >& a, T L, T R) {
    vector< S > res(R - L, S(0));
    for(const T x : a) res[x - L] += 1;
    return res;
}
template < class S, class T > struct prefix_sum {
    vector< S > s;
    prefix_sum(const vector< T >& a) : s(a) {
        s.insert(s.begin(), S(0));
        for(int i : rep(a.size())) s[i + 1] += s[i];
    }
    // [L, R)
    S sum(int L, int R) { return s[R] - s[L]; }
};
#line 3 "cp-library/src/utility/heap.hpp"

template < class T > using heap_min = std::priority_queue< T, std::vector< T >, std::greater< T > >;
template < class T > using heap_max = std::priority_queue< T, std::vector< T >, std::less< T > >;

#line 27 "cp-library/src/cp-template.hpp"

#line 1 "cp-library/src/algorithm/bin_search.hpp"
template < class T, class F >
T bin_search(T ok, T ng, F f) {
    while(abs(ng - ok) > 1) {
        T mid = (ok + ng) / 2;
        (f(mid) ? ok : ng) = mid;
    }
    return ok;
}

template < class T, class F >
T bin_search_real(T ok, T ng, F f, int step = 80) {
    while(step--) {
        T mid = (ok + ng) / 2;
        (f(mid) ? ok : ng) = mid;
    }
    return ok;
}
#line 2 "cp-library/src/algorithm/argsort.hpp"

template < class T > std::vector< int > argsort(const std::vector< T > &a) {
    std::vector< int > ids((int)a.size());
    std::iota(ids.begin(), ids.end(), 0);
    std::sort(ids.begin(), ids.end(), [&](int i, int j) {
        return a[i] < a[j] || (a[i] == a[j] && i < j);
    });
    return ids;
}
#line 1 "macro.hpp"
namespace macro {

using size_type = int;
template < class container > void  sort(container& a) { std::sort(std:: begin(a), std:: end(a)); }
template < class container > void rsort(container& a) { std::sort(std::rbegin(a), std::rend(a)); }
template < class container > void reverse(container& a) { std::reverse(std::begin(a), std::end(a)); }
template < class container > void unique(container& a) {
    std::sort(std::begin(a), std::end(a));
    a.erase(std::unique(std::begin(a), std::end(a)), std::end(a));
}
template < class container > container  sorted(const container& a) { container b = a;  sort(b); return std::move(b); }
template < class container > container rsorted(const container& a) { container b = a; rsort(b); return std::move(b); }
template < class container, class compare > void sort(container& a, const compare& cmp) { std::sort(std::begin(a), std::end(a), cmp); }
template < class container, class compare > container sorted(const container& a, const compare& cmp) { container b = a; sort(b, cmp); return std::move(b); }
template < class container, class value > size_type lower_bound(const container& a, const value& x) { return std::lower_bound(std::begin(a), std::end(a), x) - std::begin(a); }
template < class container, class value > size_type upper_bound(const container& a, const value& x) { return std::upper_bound(std::begin(a), std::end(a), x) - std::begin(a); }

const std::vector<std::pair<size_type, size_type>> dir4 = { {+1,  0}, {-1,  0}, { 0, +1}, { 0, -1} };
const std::vector<std::pair<size_type, size_type>> dir8 = { {-1, -1}, {-1,  0}, {-1, +1}, { 0, -1}, { 0, +1}, {+1, -1}, {+1,  0}, {+1, +1} };

#ifdef _DEBUG
#define debug(x) std::cout << "[" << __LINE__ << "] " << #x << ": " << x << std::endl
#else
#define debug(x)
#endif

template < class container > void concat(container& a, const container& b) {
    a.insert(std::end(a), std::begin(b), std::end(b));
}
std::vector<size_type> iota(const size_type n) {
    std::vector<size_type> I(n);
    std::iota(std::begin(I), std::end(I), 0);
    return I;
}
template < class container > std::vector<size_type> sort_idx(const container& a) {
    const size_type n = a.size();
    std::vector<size_type> I = iota(n);
    std::sort(std::begin(I), std::end(I), [&](size_type i, size_type j) { return a[i] < a[j] or (a[i] == a[j] and i < j); });
    return I;
}
template < class container, class compare > std::vector<size_type> sort_idx(const container& a, const compare& cmp) {
    const size_type n = a.size();
    std::vector<size_type> I = iota(n);
    std::sort(std::begin(I), std::end(I), [&](size_type i, size_type j) { return cmp(a[i], a[j]) or (a[i] == a[j] and i < j); });
    return std::move(I);
}

struct grid {
    using size_type = int;
    size_type H, W;
    grid(const size_type H, const size_type W) : H(H), W(W) {}
    bool contains(const size_type i, const size_type j) {
        return 0 <= i and i < H and 0 <= j and j < W;
    }
};

} // namespace macro

using namespace macro;
#line 3 "A.cpp"

int get_x(int N, i64 L, vector<pair<i64,i64>> seg) {
    sort(seg);
    int ans = 0, i = 0;
    i64 nowL = 0;
    while(nowL < L) {
        ans++;
        i64 nxtL = nowL;
        while(i < N and seg[i].first <= nowL) {
            chmax(nxtL, seg[i].second);
            i++;
        }
        nowL = nxtL;
    }
    return ans;
}

int get_y(int N, i64 L, vector<pair<i64,i64>> seg) {
    vector<i64> v;
    v.push_back(0);
    v.push_back(L);
    for(auto [l, r] : seg) {
        v.push_back(l);
        v.push_back(r);
    }
    unique(v);
    const int m = v.size();
    vector<i64> a(m, 0);
    for(auto [l, r] : seg) {
        l = lower_bound(v, l);
        r = lower_bound(v, r);
        a[l]++, a[r]--;
    }
    for(int i : rep(m - 1)) a[i + 1] += a[i];
    a.pop_back();
    i64 min = min_of(a).val;
    return N - min + 1;
}

int main() {
    int N = in(); i64 L = in();
    vector<pair<i64,i64>> seg(N);
    for(auto &[l, r] : seg) l = in(), r = in();
    print(get_x(N, L, seg), get_y(N, L, seg));
}
accuracy: 1
time_ms: 90
memory_kb: 15604
final_rank: 2

code_snippet: #include "bits/stdc++.h"

using namespace std;

using ll=long long;

void solve(){
    ll n,L;cin>>n>>L;
    vector<ll>l(n),r(n);
    map<ll,int>mp;
    for (int i = 0; i < n; ++i) {
        cin>>l[i]>>r[i];
        mp[l[i]]=1;
        mp[r[i]]=1;
    }
    int now=0;
    for(auto&[i,val]:mp){
        val=now++;
    }
    vector<int>mx_r(now);
    vector<int>imos(now);
    for (int i = 0; i <now; ++i) {
        mx_r[i]=i;
    }
    for (int i = 0; i < n; ++i) {
        auto l2=mp[l[i]],r2=mp[r[i]];
        mx_r[l2]=max(mx_r[l2],r2);
        imos[l2]++;
        if(r2+1<now)imos[r2+1]--;
    }
    for (int i =1; i <now; ++i) {
        mx_r[i]=max(mx_r[i-1],mx_r[i]);
        imos[i]+=imos[i-1];
    }
    int y=n-*std::min_element(imos.begin(), imos.end())+1;
    int x=0;
    int now2=0;
    while(now2!=now-1){
        x++;
        now2=mx_r[now2];
//        cerr<<"x: "<<x<<" now2:"<<now2<<" now: "<<now<<"\n";
    }
    cout<<x<<" "<<y<<"\n";
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    solve();
}
accuracy: 1
time_ms: 290
memory_kb: 33016
final_rank: 15