Q-4-20 假解

mail@pastecode.io avatar
unknown
c_cpp
2 years ago
774 B
131
Indexable
Never
#include <iostream>
#include <utility>
#include <algorithm>
using namespace std;

typedef pair<int, int> Seg;
#define l first
#define r second  
const int MAXN = 1e5+5;

int main(){
    int n, x, y;
    cin >> n >> x >> y;
    Seg p[MAXN] = {};
    for(int i = 0; i < n; i++)
        cin >> p[i].l >> p[i].r;
    sort(p, p+n);
    int cnt = 0, last = x, best = 0;
    for(int i = 0; i < n; i++){
        if(p[i].l <= last){
            if(p[i].r > p[best].r)
                best = i;
        }
        else{
            last = p[best].r;
            cnt++;
            if(p[i].l > last){
                cnt = -1;
                break;
            }
            else
                best = i;
        }
    }
    cout << cnt << '\n';

}