제출 #659811

#제출 시각아이디문제언어결과실행 시간메모리
659811Tenis0206Event Hopping 2 (JOI21_event2)C++11
0 / 100
3034 ms4340 KiB
#include <bits/stdc++.h> using namespace std; struct event { int l,r; }; int n,k; event v[100005]; int dp[100005]; vector<int> a; int get_val(int val) { int st = 1; int dr = a.size(); int poz = 0; while(st<=dr) { int mij = (st + dr) >> 1; if(a[mij-1]<=val) { poz = mij; st = mij + 1; } else { dr = mij - 1; } } return poz; } int main() { ios::sync_with_stdio(false); cin.tie(0); cin>>n>>k; for(int i=1;i<=n;i++) { cin>>v[i].l>>v[i].r; a.push_back(v[i].l); a.push_back(v[i].r); } sort(a.begin(),a.end()); for(int i=1;i<=n;i++) { v[i].l = get_val(v[i].l); v[i].r = get_val(v[i].r); } sort(v+1,v+n+1,[](event a, event b){return a.l<=b.l;}); int poz = 0; for(int i=n;i>=1;i--) { dp[i] = 1; for(int j=i+1;j<=n;j++) { if(v[j].l >= v[i].r) { dp[i] = max(dp[i], 1 + dp[j]); } } if(dp[i] >= k) { poz = i; } } if(!poz) { cout<<-1<<'\n'; return 0; } --k; vector<int> rez; rez.push_back(poz); while(k) { for(int j=poz+1;j<=n;j++) { if(v[j].l >= v[poz].r && dp[j]>=k) { poz = j; break; } } rez.push_back(poz); --k; } for(auto it : rez) { cout<<it<<'\n'; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...