Cod sursa(job #3334067)
| Utilizator | Data | 16 ianuarie 2026 09:14:50 | |
|---|---|---|---|
| Problema | Subsir crescator maximal | Scor | 0 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.93 kb |
#include <iostream>
using namespace std;
int v[100001], z, ans[100001], rec[100001], pstart, ans2[100001];
int main()
{
int n;
cin >> n;
for(int i = 1; i<=n; i++)
{
cin >> v[i];
}
for(int i = 1; i<=n; i++)
{
int x = v[i];
if(z == 0)
{
ans[++z] = x;
}
else
{
int poz = lower_bound(ans+1, ans+1+z, x) - ans;
if(poz > z)
{
pstart = i;
ans[++z] = x;
}
else
{
ans[poz] = x;
}
}
rec[i] = z;
}
cout << z << '\n';
int m = 0;
for(int i = pstart; i>0; i--)
{
if(rec[i] == z)
{
ans2[++m] = v[i];
z--;
}
}
for(int i = m ; i>0; i--)
{
cout << ans2[i] << ' ';
}
return 0;
}
