This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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++;
}
cur = nxt;
banyak++;
if(l == n && cur < vai[i].fi + m){
bisa = false;
break;
}
}
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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |