Submission #1144198

#TimeUsernameProblemLanguageResultExecution timeMemory
1144198antonnEvent Hopping 2 (JOI21_event2)C++20
0 / 100
3094 ms2372 KiB
#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) {
            x = i;
            break;
        }
    }
    if (x == -1) {
        cout << -1 << "\n";
        return 0;
    }
    
    vector<int> v;
    v.push_back(a[x][2]);
    int last = x;
    k--;
    for (int i = x + 1; i <= n; ++i) {
        if (k == 0) break;
        if (a[i][0] >= a[last][1] && dp[i] >= k) {
            v.push_back(a[i][2]);
            last = i;
            --k;
        }
    }
    
    // reverse(v.begin(), v.end());
    sort(v.begin(), v.end());
    for (auto i : v) cout << i << "\n";
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...