GzhuOJ_Good Sequence
#include<stdio.h> int main() { int S[5005],d[5005]; int n; while(~scanf("%d",&n)) { for(int i=0;i<n;++i) scanf("%d",&S[i]); d[0]=-1; d[1]=S[0]; int len=1,l,r,mid; for(int i=1;i<n;++i) { l=0,r=len; while(l<=r) { mid=(l+r)>>1; if(d[mid]<=S[i]) l=mid+1; else r=mid-1; } d[l]=S[i]; if(l>len) len++; } printf("%d\n",n-len); } return 0; }