Pagini recente » Cod sursa (job #586514) | Cod sursa (job #2844069) | Cod sursa (job #1193208) | Cod sursa (job #173829) | Cod sursa (job #1885863)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("scmax.in");
ofstream fout("scmax.out");
int best[100010], p[100010];
int n, v[100010], n_max, p_max;
vector<int> sol;
int main()
{
fin >> n;
for(int i=1; i<=n; i++){
fin >> v[i];
best[i] = 1;
}
n_max = 1; p_max = 1;
for(int i=2; i<=n; i++)
{
for(int j=1; j<i; j++)
if(v[j] < v[i] && best[i] < best[j]+1){
best[i] = best[j] + 1;
p[i] = j;
}
if(best[i] > n_max)
{
n_max = best[i];
p_max = i;
}
}
while(p_max != 0)
{
sol.push_back(p_max);
p_max = p[p_max];
}
sort(sol.begin(), sol.end());
fout<<sol.size()<<'\n';
for(auto it:sol)
fout<<v[it]<<' ';
return 0;
}