Pagini recente » Cod sursa (job #1556224) | Cod sursa (job #2314969) | Cod sursa (job #2768321) | Cod sursa (job #539124) | Cod sursa (job #1853312)
#include <iostream>
#include <fstream>
using namespace std;
int n, v[100005], best[100005], maxL = 1, poz_maxL, poz[100005];
void read()
{
ifstream fin("scmax.in");
fin >> n;
for(int i = 1; i <= n; ++i)
fin >> v[i];
}
void solve()
{
best[n] = 1;
poz[n] = -1;
poz_maxL = n;
for(int i = n - 1; i >= 1; --i){
best[i] = 1;
for(int j = i + 1; j <= n; ++j)
if(v[i] < v[j] && best[j] + 1 > best[i]){
best[i] = best[j] + 1;
poz[i] = j;
}
if(best[i] > maxL){
maxL = best[i];
poz_maxL = i;
}
}
}
void write()
{
ofstream fout("scmax.out");
fout << maxL << '\n';
for(int i = 1; i <= maxL; ++i){
fout << v[poz_maxL] << ' ';
poz_maxL = poz[poz_maxL];
}
}
int main()
{
read();
solve();
write();
return 0;
}