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;
const int INF = 1e9 + 12345;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, k;
cin >> n >> k;
vector<array<int, 2>> a(n);
for (int i = 0; i < n; i++) {
int l, r;
cin >> l >> r;
a[i] = {l, r};
}
vector<int> key(k, INF);
for (int mask = 0; mask < (1 << n); mask++) {
if (__builtin_popcount(mask) != k) continue;
vector<int> seq;
vector<array<int, 2>> fetch;
for (int i = 0; i < n; i++) {
if (mask >> i & 1) {
seq.push_back(i);
fetch.push_back(a[i]);
}
}
sort(fetch.begin(), fetch.end());
bool ok = true;
for (int i = 1; i < k; i++) {
if (fetch[i][0] < fetch[i - 1][1]) {
ok = false;
}
}
if (ok) {
key = min(key, seq);
}
}
if (key[0] == INF) {
cout << -1 << '\n';
} else {
for (int i : key) {
cout << i + 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... |