Submission #1144196

#TimeUsernameProblemLanguageResultExecution timeMemory
1144196antonnEvent Hopping 2 (JOI21_event2)C++20
0 / 100
0 ms328 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 = 1; i <= n; ++i) {
        dp[i] = 1;
        for (int j = 1; j < i; ++j) {
            if (a[j][1] <= a[i][0] && dp[j] + 1 > dp[i]) {
                dp[i] = dp[j] + 1;
                ant[i] = j;
            }
        }
    }
    int x = -1;
    for (int i = 1; i <= n; ++i) {
        if (dp[i] >= k) {
            x = i;
        }
    }
    vector<int> v;
    while (k--) {
        v.push_back(a[x][2]);
        x = ant[x];
    }
    reverse(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...