이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 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... |