t1:
#include<cstdio> #include<cstring> const int N=1000010; int a[N],b[N]; int sum=1,maxx=0; int main() { freopen("sequence.in","r",stdin); freopen("sequence.out","w",stdout); int n; scanf("%d",&n); for(int i=1;i<=n;i++) scanf("%d %d",&a[i],&b[i]); int now=1,last=1,t=a[1]; while(now<n) { now++,sum++; if(b[now]<t) { last++;now=last;t=a[now];sum=1; } else if(t<a[now]) { t=a[now];last=now; } if(maxx<sum) maxx=sum; } printf("%d",maxx); return 0; }
贪心,注意初值;
时间: 2024-10-11 17:35:30