Cod sursa(job #2077070)
| Utilizator | Data | 27 noiembrie 2017 17:55:25 | |
|---|---|---|---|
| Problema | Subsir crescator maximal | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.68 kb |
#include <fstream>
using namespace std;
ifstream fin ("scmax.in");
ofstream fout ("scmax.out");
int v[100005], s[100005], lu[100005], t[100005], n, lmax, i, j, m;
int main ()
{
fin>>n;
for (i = 0; i < n; i ++)
{
fin>>v[i];
j = 1;
while (s[j] < v[i] && j <= lmax)
j ++;
s[j] = v[i];
lu[i] = j;
if (j > lmax)
lmax = j;
}
fout<<lmax<<'\n';
m = lmax;
for (i = n; i >= 0; i --)
{
if (lu[i] == lmax)
t[lmax--] = v[i];
}
for (i = 1; i <= m; i ++)
fout<<t[i]<<" ";
fin.close();
fout.close();
return 0;
}
