Cod sursa(job #2251127)
Utilizator | Data | 1 octombrie 2018 10:05:36 | |
---|---|---|---|
Problema | Subsir crescator maximal | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.34 kb |
#import<fstream>
std::ifstream f("scmax.in");std::ofstream g("scmax.out");const int N=2e5;int n,i,j,a[N],b[N],poz[N],Z[N],S,D,k,M;int main(){for(f>>n,i=1;i<=n;){f>>a[i],S=1,D=k;while(S<=D){if(b[M=(S+D)/2]<a[i])S=M+1;else D=M-1;}if (S>k)k++;b[S]=a[i],poz[i++]=S;}for(i=n;i>=1&&k;i--)if(poz[i]==k)Z[++j]=a[i],k--;for(g<<j<<'\n';j;g<<Z[j--]<<" ");}