제출 #1144457

#제출 시각아이디문제언어결과실행 시간메모리
1144457antonnEvent Hopping 2 (JOI21_event2)C++20
0 / 100
3096 ms2628 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), mn(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]) {
                if (dp[j] + 1 > dp[i]) {
                    dp[i] = dp[j] + 1;
                    mn[i] = min(mn[j], a[i][2]);
                } else if (dp[j] + 1 == dp[i]) {
                    mn[i] = min(mn[i], min(mn[j], a[i][2]));
                }
            }
        }
    }
    int x = -1;
    for (int i = 1; i <= n; ++i) {
        if (dp[i] >= k) {
            if (x == -1 || mn[i] < mn[x]) x = i;
        }
    }
    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 || mn[j] < mn[best]) 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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...