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;
using ll = long long;
#define all(x) (x).begin(), (x).end()
int main() {
cin.tie(0)->sync_with_stdio(false);
int n, k;
cin >> n >> k;
vector<array<int, 2>> a(n);
for (auto &[l, r] : a)
cin >> l >> r;
vector<array<int, 2>> b = a;
sort(all(b), [&](array<int, 2> &x, array<int, 2> &y) { return x[1] < y[1]; });
vector<int> ans;
for (int i = 0; i < n; i++) {
if (ans.size() == k || !count(all(b), a[i]))
continue;
vector<array<int, 2>> c;
for (auto &[l, r] : b)
if (r <= a[i][0] || l >= a[i][1])
c.push_back({l, r});
int cnt = 0, p = -1;
for (auto &[l, r] : c) {
if (l >= p)
cnt++, p = r;
}
if (cnt + ans.size() + 1 >= k) {
ans.push_back(i + 1);
b = c;
}
}
if (ans.size() < k)
cout << -1 << '\n';
else {
for (int i : ans)
cout << i << '\n';
}
return 0;
}
Compilation message (stderr)
event2.cpp: In function 'int main()':
event2.cpp:22:24: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
22 | if (ans.size() == k || !count(all(b), a[i]))
| ~~~~~~~~~~~^~~~
event2.cpp:36:34: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
36 | if (cnt + ans.size() + 1 >= k) {
| ~~~~~~~~~~~~~~~~~~~~~^~~~
event2.cpp:42:20: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
42 | if (ans.size() < k)
| ~~~~~~~~~~~^~~
# | 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... |