Pagini recente » Cod sursa (job #1190790) | Cod sursa (job #866619) | Cod sursa (job #242809) | Cod sursa (job #1104267) | Cod sursa (job #3324199)
/******************************************************************************
Online C++ Compiler.
Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.
*******************************************************************************/
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
int main()
{
ifstream f("scmax.in");
ofstream g("scmax.out");
int n;
f>>n;
vector<int> v(n), best(n);
for(int i=0; i<n; i++)
{
f>>v[i];
}
for(int i=0; i<n-1; i++)
{
for(int j=i+1; j<n; j++)
{
if(v[i]<v[j])
{
best[j] = max(best[j], best[i] + 1);
}
}
}
int aux=0;
for(int i=0; i<n; i++)
{
if(aux<best[i])
{
aux=best[i];
}
}
g<<aux+1<<endl;
vector<int> v2;
for(int i=n-1; i>=0; i--)
{
if(best[i]==aux)
{
v2.push_back(v[i]);
aux--;
}
}
for(int i=v2.size()-1; i>=0; i--)
{
g<<v2[i]<<" ";
}
return 0;
}