제출 #1066822

#제출 시각아이디문제언어결과실행 시간메모리
1066822vjudge1Fire (BOI24_fire)C++17
40 / 100
2098 ms2788 KiB
#include <bits/stdc++.h>
#define ll long long
#define endl "\n"
#define fi first 
#define se second

using namespace std;


int n, m;

void solve(){
    cin >> n >> m;
    vector<pair<int, int>> vai(n);
    for(int i = 0; i < n; i++){
        cin >> vai[i].fi >> vai[i].se;
    }
    sort(vai.begin(), vai.end());

    for(int i = 0; i < n; i++){
        if(vai[i].se < vai[i].fi){
            vai[i].se += m;
        }
    }

    int res = 1e9;
    for(int i = 0; i < n; i++){
    
        int l = 0;
        int banyak = 1;
        int nxt = vai[i].se;
        int cur = vai[i].se;
        bool bisa = true;
        while(cur < vai[i].fi + m){
            while(l < n && vai[l].fi <= cur){
                nxt = max(nxt, vai[l].se);
                l++;
            }
            if((l == n && nxt < vai[i].fi + m) || (nxt == cur)){
                bisa = false;
                break;
            }
            cur = nxt;
            banyak++;
            
        }
        if(bisa){
            res = min(res, banyak);
        }
    }
    if(res != 1e9){
        cout << res << endl;
    }else{
        cout << -1 << endl;
    }
    
    

}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int t = 1;
    while(t--){
        solve();
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...