#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
using ll = long long;
using pi = pair<int, int>;
using vi = vector<int>;
template<class T> bool ckmin(T& a, T b) { return b < a ? a = b, true : false; }
template<class T> bool ckmax(T& a, T b) { return a < b ? a = b, true : false; }
int main() {
ios::sync_with_stdio(0); cin.tie(0);
int n, k; cin >> n >> k;
vector<array<int, 3>> a(n + 1);
for (int i = 1; i <= n; ++i) cin >> a[i][0] >> a[i][1], a[i][2] = i;
sort(a.begin() + 1, a.end());
vector<int> dp(n + 1), ant(n + 1);
for (int i = n; i >= 1; --i) {
dp[i] = 1;
for (int j = i + 1; j <= n; ++j) {
if (a[j][0] >= a[i][1] && dp[j] + 1 > dp[i]) {
dp[i] = dp[j] + 1;
}
}
}
int x = -1;
for (int i = 1; i <= n; ++i) {
if (dp[i] >= k) {
if (x == -1 || a[i][2] < a[x][2]) x = i;
break;
}
}
if (x == -1) {
cout << -1 << "\n";
return 0;
}
vector<int> v;
v.push_back(a[x][2]);
int last = x;
k--;
int i = x + 1;
while (i <= n) {
if (k == 0) break;
int best = -1;
for (int j = i; j <= n; ++j) {
if (a[j][0] >= a[last][1] && dp[j] >= k) {
if (best == -1 || a[last][2] < a[best][2]) best = j;
}
}
v.push_back(a[best][2]);
last = best;
i = best + 1;
--k;
}
// reverse(v.begin(), v.end());
sort(v.begin(), v.end());
for (auto i : v) cout << i << "\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... |