Pagini recente » Cod sursa (job #2810411) | Cod sursa (job #914197) | Cod sursa (job #2783058) | Cod sursa (job #615376) | Cod sursa (job #2977403)
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long
#define all(v) v.begin(), v.end()
#define fr(n) for(ll i=0;i<n;++i)
#define ctz(x) __builtin_ctzll(x)
#define clz(x) __builtin_clzll(x)
#define pcount(x) __builtin_popcountll(x)
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
#define cin fin
#define cout fout
ifstream fin("scmax.in");
ofstream fout("scmax.out");
void solve(){
ll n;cin>>n;
ll a[n+1];
a[0]=0;
for(ll i=1; i<=n; i++){
cin>>a[i];
}
vector<ll> dp(n+1, 0);
ll temp=0;
for(ll i=1; i<=n;i++){
for(ll j=i-1; j>=0;j--){
if(a[j]<a[i]) dp[i]=max(dp[i], dp[j]+1);
}
temp=max(temp, dp[i]);
}
cout<<temp<<"\n";
ll cnt=INT_MAX;
vector<ll> v;
for(ll i=n; i>0; i--){
if(dp[i]==temp && a[i]<cnt){
// cout<<a[i]<<" ";
v.push_back(a[i]);
cnt=a[i];
temp--;
}
}
reverse(all(v));
fr(v.size()){
cout<<v[i]<<" ";
}
}
int main(){
// ios_base::sync_with_stdio(false); cin.tie(NULL);
// ll t;cin>>t;while(t--){solve();cout<<endl;}
solve();
}