Submission #575242

#TimeUsernameProblemLanguageResultExecution timeMemory
575242balbitEvent Hopping 2 (JOI21_event2)C++14
32 / 100
130 ms1236 KiB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define pii pair<int, int>
#define f first
#define s second

#define REP(i,n) for (int i = 0; i<n; ++i)
#define REP1(i,n) for (int i = 1; i<=n; ++i)

#define MX(a,b) a = max(a,b)
#define MN(a,b) a = min(a,b)
#define pb push_back
#define SZ(x) (int)(x).size()
#define ALL(x) (x).begin(), (x).end()

#ifdef BALBIT
#define bug(...) cerr<<"#"<<__LINE__<<": "<<#__VA_ARGS__<<"- ", _do(__VA_ARGS__)
template<typename T> void _do(T && x) {cerr<<x<<endl;}
template<typename T, typename ...S> void _do(T && x, S && ...y) {cerr<<x<<", "; _do(y...);}
#else
#define bug(...)

#endif // BALBIT

const int maxn = 6e3+5;

bool ban[maxn];
int ps[maxn];
pii v[maxn];
ll dp[maxn];
vector<int> upd[maxn];

int tryrem(int x) {
    for (int j = v[x].f+1; j<=v[x].s; ++j) {
        if (ban[j]) return -maxn;
    }
    for (int j = v[x].f+1; j<=v[x].s; ++j) {
        ban[j] = 1;
    }
    for (int i = 1; i<maxn; ++i) {
        ps[i] = ps[i-1] + ban[i];
    }
    ll re = 0;
    for (int i = 1; i<maxn; ++i) {
        dp[i] = 0;
        MX(dp[i], dp[i-1]);
        for (int l : upd[i]) {
            if (ps[i] - ps[l]) continue;
            MX(dp[i], dp[l] + 1);
        }
        MX(re, dp[i]);
    }
    for (int j = v[x].f+1; j<=v[x].s; ++j) {
        ban[j] = 0;
    }
    return re;
}

signed main(){
    ios::sync_with_stdio(0), cin.tie(0);

    bug(1,2);

    int n,k; cin>>n>>k;

    vector<int> xpos;

    REP(i,n) {
        cin>>v[i].f>>v[i].s;
        xpos.pb(v[i].f); xpos.pb(v[i].s);
    }
    sort(ALL(xpos));
    xpos.resize(unique(ALL(xpos)) - xpos.begin());

    REP(i, n) {
        pii &p = v[i];
        p.f = lower_bound(ALL(xpos), p.f) - xpos.begin();
        p.s = lower_bound(ALL(xpos), p.s) - xpos.begin();
        bug(p.f, p.s);
        upd[p.s].pb(p.f);
    }

    vector<int> took;
    for (int i = 0; i<n; ++i) {
        if (tryrem(i) + 1 + SZ(took) >= k) {
            // ok!
            took.pb(i);
            bug(i);
            for (int j = v[i].f+1; j<=v[i].s; ++j) {
                ban[j] = 1;
            }
        }else{

        }
    }

    if (k <= SZ(took)) {
        REP(i,k) cout<<took[i]+1<<endl;
    }else{
        cout<<-1<<endl;
    }


}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...