Cod sursa(job #3213616)
Utilizator | TanasucaGeorgeAlexandru TanasucaGeorgeAlexandru | Data | 13 martie 2024 12:15:30 |
---|---|---|---|
Problema | Subsir crescator maximal | Scor | 10 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.78 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream fin("scmax.in");
ofstream fout("scmax.out");
int a[100005];
int s[100005];
int n,st,dr,m,top,p;
int main()
{
int i,x;
fin >> n;
for(i=1;i<=n;i++){
fin >> a[i];
}
s[1]=a[1];
top=1;
for(i=2;i<=n;i++){
x=a[i];
if(x<s[1]) s[1]=x;
else if(x>s[top])
s[++top]=x;
else{
st=1;
dr=top;
while(st<=dr){
m=(st+dr)/2;
if(x<=s[m]){
p=m;
st=m+1;
}
else dr=m-1;
}
s[p]=x;
}
}
fout << top << "\n";
for(i=1;i<=top;i++) fout <<s[i] << " ";
return 0;
}