greedy
For the first illegal position, we obviously want to delete a few by covering its range to make the legal position
Obviously the right to delete point further to the right intervals is better, so we consider a priority right point right to delete, and then consider an illegal position
With a $ set $ maintenance at the right point and interval number can be
#include<iostream> #include<cstdio> #include<algorithm> #include<cstring> #include<cmath> #include<vector> #include<set> using namespace std; typedef long long ll; inline int read() { int x=0,f=1; char ch=getchar(); while(ch<'0'||ch>'9') { if(ch=='-') f=-1; ch=getchar(); } while(ch>='0'&&ch<='9') { x=(x<<1)+(x<<3)+(ch^48); ch=getchar(); } return x*f; } const int N=2e5+7; int n,m; struct dat { int r,id; dat (int _r=0,int _id=0) { r=_r,id=_id; } inline bool operator < (const dat &tmp) const { return r!=tmp.r ? r<tmp.r : id<tmp.id; } }; vector <dat> V[N]; vector <int> mov; set <dat> S; int main() { n=read(),m=read(); int a,b,mx=0; for(int i=1;i<=n;i++) a=read(),b=read(), mx=max(mx,b), V[a].push_back(dat(b,i)); int ans=0; for(int i=1;i<=mx;i++) { while(S.size()&&(*S.begin()).r<i) S.erase(S.begin()); for(auto x: V[i]) S.insert(dat(x.r,x.id)); while(S.size()>m) { auto p=S.rbegin(); ans++,mov.push_back((*p).id); S.erase(*p); } } printf("%d\n",ans); for(auto x: mov) printf("%d ",x); puts(""); return 0; }