Cod sursa(job #2135103)
| Utilizator | Data | 18 februarie 2018 16:37:43 | |
|---|---|---|---|
| Problema | Subsir crescator maximal | Scor | 65 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.61 kb |
//#include <iostream>
#include <fstream>
using namespace std;
ifstream f("scmax.in");
ofstream cout("scmax.out");
int n, a[100005], viz[100005], poz[100005], lmax;
void out(int i, int l)
{
while (poz[i]!=l) i--;
if (l>1) out(i-1, l-1);
cout<<a[i]<<" ";
}
int main()
{
int i, j;
f>>n;
for (i=1; i<=n; i++)
{
f>>a[i];
j=1;
while (a[i]>viz[j] && j<=lmax) j++;
poz[i]=j;
viz[j]=a[i];
lmax=max(j,lmax);
}
cout<<lmax<<"\n";
//out(n, lmax);
for (i=1; i<=lmax; i++) cout<<viz[i]<<" ";
return 0;
}
