This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define TRACE(x) cerr << #x << " :: " << x << endl
#define _ << " " <<
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define RFOR(i,a,b) for(int i=(a);i>=(b);--i)
typedef long long ll;
typedef pair<int,int> ii;
const int mxN = 1e5+5;
const int mxK = 1e5+5;
int N, K;
ii events[mxN];
int dp[mxN], mx[mxN];
int main() {
ios::sync_with_stdio(0); cin.tie(0);
cin >> N >> K;
FOR(i,1,N){
int L, R; cin >> L >> R;
events[i] = ii(L,R);
}
dp[N+1] = mx[N+1] = 0;
dp[N] = mx[N] = 1;
RFOR(i,N-1,1){
auto it = lower_bound(events+1,events+1+N,ii(events[i].second,0))-events;
dp[i] = mx[it]+1;
mx[i] = max(mx[i+1], dp[i]);
}
vector<int> ans;
FOR(i,1,N){
if (ans.empty() || events[ans.back()].second <= events[i].first) {
if (SZ(ans) + dp[i] >= K) {
ans.push_back(i);
}
}
if (SZ(ans) == K) break;
}
if (SZ(ans) < K) {
cout << -1 << '\n';
} else {
for (int& x : ans) {
cout << x << '\n';
}
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |