Pagini recente » Cod sursa (job #2979506) | Cod sursa (job #881003) | Cod sursa (job #2577681) | Cod sursa (job #532119) | Cod sursa (job #3264104)
#include <bits/stdc++.h>
using namespace std;
ifstream fin ("scmax.in");
ofstream fout("scmax.out");
int n, ans, p;
const int Max = 1e5 + 1;
vector<int> a(Max), dp(Max), parent(Max);
stack<int> s;
int main()
{
ios::sync_with_stdio(false);
fin.tie(NULL);
fin >> n;
for(int i = 1; i <= n; ++i)
fin >> a[i];
for(int i = 1; i <= n; ++i)
{
int x = 0;
for(int j = 1; j < i; ++j)
if(a[j] > x && a[j] < a[i])
{
x = a[j];
parent[i] = j;
}
dp[i] = 1 + dp[parent[i]];
if(dp[i] > ans)
{
ans = dp[i];
p = i;
}
}
fout << ans << "\n";
for(int i = p; i; i = parent[i])
s.push(i);
while(!s.empty())
{
fout << a[s.top()] << " ";
s.pop();
}
fin.close();
fout.close();
return 0;
}