Pagini recente » Cod sursa (job #2322806) | Cod sursa (job #2257159) | Cod sursa (job #2427168) | Cod sursa (job #308146) | Cod sursa (job #2505425)
#include <iostream>
#include <fstream>
#include <algorithm>
using namespace std;
ifstream fin ("scmax.in");
ofstream fout ("scmax.out");
int a[100005];
int s[100005];
int dp[100005];
int n, nq;
int main()
{
fin >> n;
for(int i = 0; i < n; i++)
fin >> a[i];
for(int i = 0; i < n; i++)
{
int mmm = 0;
for(int j = 0; j < i; j++)
{
if(a[j] < a[i])
{
mmm = max(s[j], mmm);
}
}
s[i] = mmm+1;
}
int mx, pos;
mx = 0;
for(int i = 0; i < n; i++)
{
if(s[i] > mx)
{
mx = s[i];
pos = i;
}
}
fout << mx << "\n";
dp[nq++] = a[pos];
for(int i = pos; i >= 0; i--)
{
if(a[i] < a[pos] && s[i] == s[pos]-1)
{
pos = i;
dp[nq++] = a[i];
}
}
for(int i = nq-1; i >= 0; i--)
fout << dp[i] << " ";
return 0;
}