이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> ii;
typedef tuple<ll,ll,ll> iii;
//get<0>(v[i])
ll n,k,a[3010],b[3010],id[3010];
ii h[3010];
vector<ii> v;
//end,start
bool cmp(int x, int y){
return a[x]<a[y];
}
int longest(int x){
int i=0;
int j=0;
//printf("starting with %d:\n",x);
while(i<n-1&&j<k){
while(i<n-1&&h[i].second<x)i++;
if(h[i].second<x)continue;
x=h[i].first;
j++;
//cout<<h[i].first<<" "<<h[i].second<<endl;
}
//cout<<j<<endl<<endl;
return j;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
cin>>n>>k;
for(int i=0; i<n; i++){
cin>>h[i].second>>h[i].first;
a[i]=h[i].second;
b[i]=h[i].first;
id[i]=i;
}
sort(h, h+n);
sort(id,id+n,cmp);
if(longest(0)<k){
cout<<-1;
return 0;
}
for(int i=0; i<n; i++){
//if(v.size()>0)cout<<a[id[i]]<<" "<<v[v.size()-1].second<<endl;
if((v.size()==0||a[id[i]]>=v[v.size()-1].second)&&longest(b[id[i]])>=k-id[i]-1){
v.push_back(ii(i,b[id[i]]));
}
}
for(auto it: v){
cout<<it.first+1<<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... |