Pagini recente » Cod sursa (job #1480094) | Cod sursa (job #1065683) | Cod sursa (job #1370972) | Cod sursa (job #2634726) | Cod sursa (job #2664804)
#include<bits/stdc++.h> //:3
using namespace std;
typedef long long LL;
#define all(a) (a).begin(), (a).end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pi pair<int, int>
#define sz(x) (int)((x).size())
#define int long long
#define cin in
#define cout out
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const LL inf = 2e6;
const LL mod = 1e9 + 7;
const int N = 2e6 + 11;
const LL INF64 = 3e18 + 1;
const double eps = 1e-14;
const double PI = acos(-1);
int n, a[N], dp[N], ind[N], p[N];
ifstream in("scmax.in");
ofstream out("scmax.out");
void solve(){
cin >> n;
for(int i = 1; i <= n; i++)dp[i] = INF64;
int ans = 0;
for(int i = 1; i <= n; i++){
cin >> a[i];
int x = lower_bound(dp + 1, dp + n + 1, a[i]) - dp;
p[i] = ind[x - 1];
ind[x] = i;
dp[x] = a[i];
ans = max(ans, x);
}
cout << ans << '\n';
vector<int> v;
int lst = ind[ans];
while(lst != 0){
v.pb(a[lst]);
lst = p[lst];
}
reverse(all(v));
for(auto it : v)cout << it << ' '; cout << '\n';
}
int32_t main(){
ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
//cout << setprecision(6) << fixed;
int T = 1;
//cin >> T;
while(T--){
solve();
}
}