提交时间:2022-07-19 12:24:35

运行 ID: 52503

#include <iostream> #include <algorithm> using namespace std; const int N = 500010; struct Wood { int a,b; }w[N]; int ls[N],f[N],pos[N],ar[N]; bool cmp(const Wood& x,const Wood& y) { if(x.a != y.a) return x.a > y.a; else return x.b > y.b; } int main() { int n,i,j,ans = 0; cin>>n; for(i = 1;i <= n;i++) cin>>w[i].a>>w[i].b; sort(w + 1,w + n + 1,cmp); for(i = 1;i <= n;i++) { if(w[i].b >= pos[ans]) pos[++ans] = w[i].b; else { int j = lower_bound(pos + 1,pos + ans + 1,w[i].b) - pos; pos[j] = w[i].b; } } cout<<ans<<endl; }