#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
#define ld long double
#define pii pair<int, int>
#define f first
#define s second
#define boost() cin.tie(0), cin.sync_with_stdio(0)
bool cmp(pii p, pii q) {
return p.s < q.s;
}
const int MN = 200005;
int n, k, vis[MN], dp1[MN], dp2[MN];
pii a[MN];
vector<int> xs, ls[MN], rs[MN];
map<int, int> mp;
int32_t main() {
boost();
cin >> n >> k;
for (int i = 1; i <= n; i++) {
cin >> a[i].f >> a[i].s;
xs.push_back(a[i].f);
xs.push_back(a[i].s);
}
sort(xs.begin(), xs.end());
xs.erase(unique(xs.begin(), xs.end()), xs.end());
for (int i = 0; i < xs.size(); i++) mp[xs[i]] = i + 1;
for (int i = 1; i <= n; i++) a[i].f = mp[a[i].f], a[i].s = mp[a[i].s];
vector<int> out;
for (int i = 1; i <= n; i++) {
ls[a[i].s].push_back(a[i].f);
rs[a[i].f].push_back(a[i].s);
}
for (int i = 1; i <= xs.size(); i++) {
dp1[i] = dp1[i - 1];
for (int p : ls[i]) dp1[i] = max(dp1[i], dp1[p] + 1);
}
for (int i = xs.size(); i > 0; i--) {
dp2[i] = dp2[i + 1];
for (int p : rs[i]) dp2[i] = max(dp2[i], dp2[p] + 1);
}
for (int c = 1; c <= k; c++) {
for (int i = 1; i <= n; i++) {
if (vis[i]) continue;
if (dp1[a[i].f] + dp2[a[i].s] >= k - c) {
for (int j = a[i].s; j <= xs.size(); j++) dp1[j]--;
for (int j = 1; j <= a[i].f; j++) dp2[j]--;
vis[i] = 1;
for (int j = 1; j <= n; j++) {
if (a[j].f >= a[i].s || a[j].s <= a[i].f) continue;
vis[j] = 1;
}
out.push_back(i);
break;
}
}
if (out.size() < c) return 0 * printf("-1\n");
}
for (int p : out) printf("%lld\n", p);
return 0;
}
Compilation message
event2.cpp: In function 'int32_t main()':
event2.cpp:34:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
34 | for (int i = 0; i < xs.size(); i++) mp[xs[i]] = i + 1;
| ~~^~~~~~~~~~~
event2.cpp:41:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
41 | for (int i = 1; i <= xs.size(); i++) {
| ~~^~~~~~~~~~~~
event2.cpp:53:40: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
53 | for (int j = a[i].s; j <= xs.size(); j++) dp1[j]--;
| ~~^~~~~~~~~~~~
event2.cpp:64:24: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
64 | if (out.size() < c) return 0 * printf("-1\n");
| ~~~~~~~~~~~^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9676 KB |
Output is correct |
2 |
Correct |
5 ms |
9676 KB |
Output is correct |
3 |
Correct |
6 ms |
9676 KB |
Output is correct |
4 |
Execution timed out |
3095 ms |
36796 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
9676 KB |
Output is correct |
2 |
Correct |
5 ms |
9676 KB |
Output is correct |
3 |
Correct |
6 ms |
9676 KB |
Output is correct |
4 |
Correct |
6 ms |
9676 KB |
Output is correct |
5 |
Correct |
6 ms |
9636 KB |
Output is correct |
6 |
Correct |
7 ms |
9676 KB |
Output is correct |
7 |
Correct |
6 ms |
9676 KB |
Output is correct |
8 |
Correct |
5 ms |
9676 KB |
Output is correct |
9 |
Correct |
5 ms |
9676 KB |
Output is correct |
10 |
Correct |
5 ms |
9676 KB |
Output is correct |
11 |
Correct |
5 ms |
9676 KB |
Output is correct |
12 |
Correct |
6 ms |
9676 KB |
Output is correct |
13 |
Correct |
5 ms |
9676 KB |
Output is correct |
14 |
Correct |
5 ms |
9676 KB |
Output is correct |
15 |
Correct |
5 ms |
9676 KB |
Output is correct |
16 |
Correct |
6 ms |
9676 KB |
Output is correct |
17 |
Correct |
6 ms |
9676 KB |
Output is correct |
18 |
Correct |
7 ms |
9676 KB |
Output is correct |
19 |
Correct |
5 ms |
9676 KB |
Output is correct |
20 |
Correct |
5 ms |
9676 KB |
Output is correct |
21 |
Correct |
5 ms |
9676 KB |
Output is correct |
22 |
Correct |
5 ms |
9676 KB |
Output is correct |
23 |
Correct |
5 ms |
9676 KB |
Output is correct |
24 |
Correct |
6 ms |
9676 KB |
Output is correct |
25 |
Correct |
5 ms |
9676 KB |
Output is correct |
26 |
Correct |
5 ms |
9676 KB |
Output is correct |
27 |
Correct |
9 ms |
9676 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
9676 KB |
Output is correct |
2 |
Correct |
5 ms |
9676 KB |
Output is correct |
3 |
Correct |
6 ms |
9676 KB |
Output is correct |
4 |
Correct |
6 ms |
9676 KB |
Output is correct |
5 |
Correct |
6 ms |
9636 KB |
Output is correct |
6 |
Correct |
7 ms |
9676 KB |
Output is correct |
7 |
Correct |
6 ms |
9676 KB |
Output is correct |
8 |
Correct |
5 ms |
9676 KB |
Output is correct |
9 |
Correct |
5 ms |
9676 KB |
Output is correct |
10 |
Correct |
5 ms |
9676 KB |
Output is correct |
11 |
Correct |
5 ms |
9676 KB |
Output is correct |
12 |
Correct |
6 ms |
9676 KB |
Output is correct |
13 |
Correct |
5 ms |
9676 KB |
Output is correct |
14 |
Correct |
5 ms |
9676 KB |
Output is correct |
15 |
Correct |
5 ms |
9676 KB |
Output is correct |
16 |
Correct |
6 ms |
9676 KB |
Output is correct |
17 |
Correct |
6 ms |
9676 KB |
Output is correct |
18 |
Correct |
7 ms |
9676 KB |
Output is correct |
19 |
Correct |
5 ms |
9676 KB |
Output is correct |
20 |
Correct |
5 ms |
9676 KB |
Output is correct |
21 |
Correct |
5 ms |
9676 KB |
Output is correct |
22 |
Correct |
5 ms |
9676 KB |
Output is correct |
23 |
Correct |
5 ms |
9676 KB |
Output is correct |
24 |
Correct |
6 ms |
9676 KB |
Output is correct |
25 |
Correct |
5 ms |
9676 KB |
Output is correct |
26 |
Correct |
5 ms |
9676 KB |
Output is correct |
27 |
Correct |
9 ms |
9676 KB |
Output is correct |
28 |
Correct |
11 ms |
10444 KB |
Output is correct |
29 |
Incorrect |
11 ms |
10460 KB |
Output isn't correct |
30 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9676 KB |
Output is correct |
2 |
Correct |
5 ms |
9676 KB |
Output is correct |
3 |
Correct |
6 ms |
9676 KB |
Output is correct |
4 |
Execution timed out |
3095 ms |
36796 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |