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>
#define ll long long
#define pii pair<int,int>
using namespace std;
const int mxn=6e3+5;
const int inf=1e9;
int n, k;
int l[mxn], r[mxn];
bool blocked[mxn] = {};
vector<int> ord;
vector<int> en[mxn];
int ans[mxn] = {};
int get() {
int dp[mxn] = {};
for(int i = 1; i < mxn; i++) {
dp[i] = dp[i - 1];
for(int j : en[i]) if(!blocked[j]) dp[i] = max(dp[i], dp[l[j]] + 1);
}
return dp[mxn - 1];
}
int main() {
cin >> n >> k;
vector<int> v;
for(int i = 1; i <= n; i++) {
cin >> l[i] >> r[i];
v.push_back(l[i]);
v.push_back(r[i]);
}
sort(v.begin(),v.end());
v.erase(unique(v.begin(),v.end()), v.end());
for(int i = 1; i <= n; i++) {
l[i] = lower_bound(v.begin(), v.end(), l[i]) - v.begin() + 1;
r[i] = lower_bound(v.begin(), v.end(), r[i]) - v.begin() + 1;
en[r[i]].push_back(i);
}
int needed = k;
for(int i = 1; i <= n; i++) {
if(blocked[i]) continue;
if(needed <= 0) break;
bool pb[n + 1];
for(int j = 1; j <= n; j++) pb[j] = blocked[j];
blocked[i] = 1;
for(int j = 1; j <= n; j++) if(!(r[j] <= l[i] || l[j] >= r[i])) blocked[j] = 1;
if(get() >= needed - 1) {
ans[i] = 1;
needed--;
continue;
} else {
for(int j = 1; j <= n; j++) blocked[j] = pb[j];
}
}
if(needed > 0) cout<<-1<<endl;
else {
for(int i = 1; i <= n; i++) if(ans[i]) cout<<i<<endl;
}
}
# | 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... |