#include <bits/stdc++.h>
//#define home
using namespace std;
struct event
{
int l,r,poz;
};
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);
#ifdef home
freopen("nr.in","r",stdin);
freopen("nr.out","w",stdout);
#endif // home
cin>>n>>k;
for(int i=1;i<=n;i++)
{
cin>>v[i].l>>v[i].r;
v[i].poz = i;
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)
{
int new_poz = 0;
for(int j=poz+1;j<=n;j++)
{
if(v[j].l >= v[poz].r && dp[j]>=k)
{
if(v[j].poz < v[new_poz].poz || !new_poz)
{
new_poz = j;
}
}
}
poz = new_poz;
rez.push_back(poz);
--k;
}
sort(rez.begin(),rez.end());
for(auto it : rez)
{
cout<<it<<'\n';
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Execution timed out |
3052 ms |
2792 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Execution timed out |
3052 ms |
2792 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |