Cod sursa(job #2164106)
| Utilizator | Data | 12 martie 2018 21:32:16 | |
|---|---|---|---|
| Problema | Subsir crescator maximal | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.63 kb |
#include <fstream>
#include <cstring>
#include <algorithm>
#define nmax 1000010
using namespace std;
ifstream fin("scmax.in");
ofstream fout("scmax.out");
int n,i,a[nmax],lg[nmax],ind[nmax],p[nmax],ans,poz;
void afisare(int x)
{
if (x==0)
return;
afisare(p[x]);
fout << a[x] << ' ';
}
int main()
{
fin >> n;
for (i=1; i<=n; i++)
{
fin >> a[i];
int poz=lower_bound(lg+1,lg+ans+1,a[i])-lg;
lg[poz]=a[i];
ind[poz]=i;
p[i]=ind[poz-1];
if (poz>ans)
ans=poz;
}
fout << ans << '\n';
afisare(ind[ans]);
}
