Pagini recente » Cod sursa (job #1309572) | Cod sursa (job #1226014) | Cod sursa (job #3290618) | Cod sursa (job #2794641) | Cod sursa (job #1502393)
#include <bits/stdc++.h>
using namespace std;
ifstream f("scmax.in");
ofstream g("scmax.out");
int n , v[100000] , p , Max , poz[100000] , best[100000];
void citire()
{
f>>n;
for(int i=1 ; i<=n ; i++)
f>>v[i];
}
void prelucrare()
{
poz[n] = -1;
best[n] = 1;
Max = 1;
p = n;
for(int i = n - 1 ; i>=1 ;i--)
{
best[i] = 1;
poz[i] = -1;
for(int j = i + 1; j <= n ; j++)
{
if(v[i] < v[j] && best[i] < best[j] + 1)
{
best[i] = best[j] + 1;
poz[i] = j;
if(best[i] > Max)
{
p=i;
Max = best[i];
}
}
}
}
}
void afisare()
{
g<<Max<<'\n';
while(p!=-1)
{
g << v[p] <<" ";
p = poz[p] ;
}
}
int main()
{
citire();
prelucrare();
afisare();
return 0;
}