Pagini recente » Cod sursa (job #1373279) | Cod sursa (job #22747) | Cod sursa (job #1213760) | Cod sursa (job #1689514) | Cod sursa (job #1279900)
#include <fstream>
#include <iostream>
using namespace std;
ifstream f("scmax.in");
ofstream g("scmax.out");
const int NMax = 100003;
int v[NMax],best[NMax];
int main()
{
int n,poz = 1,lmax = 1;
f >> n;
for(int i = 1; i <= n; i++)
f >> v[i];
best[n] = 1;
for(int i = n - 1; i > 0; i--){
best[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;
if(best[i] > lmax)
lmax = best[i];
poz = i;
}
}
}
g << lmax << "\n";
for(int i = poz; i <= n && lmax != 0; i++){
if(best[i] == lmax){
g << v[i] << " ";
lmax--;
}
}
return 0;
}