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"
using namespace std;
#define ar array
#define int long long
signed main(){
ios::sync_with_stdio(0); cin.tie(0);
int n, k; cin>>n>>k;
vector<ar<int, 2>> a(n);
for(int i=0;i<n;i++){
cin>>a[i][0]>>a[i][1];
}
vector<int> res = {(int)1e9};
for(int mask=0;mask < (1 << n);mask++){
if(__builtin_popcount(mask) != k) continue;
vector<int> p;
for(int j=0;j<n;j++){
if(mask >> j & 1) p.push_back(j);
}
sort(p.begin(), p.end(), [&](int i, int j){
return a[i][0] < a[j][0];
});
bool ok = 1;
for(int i=1;i<k;i++){
if(a[p[i-1]][1] > a[p[i]][0]) ok = 0;
}
if(ok){
sort(p.begin(), p.end());
res = min(res, p);
}
}
if(res[0] == 1e9){
cout<<-1<<"\n";
} else {
for(auto x : res) cout<<x + 1<<"\n";
}
}
# | 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... |