Pagini recente » Cod sursa (job #901477) | Cod sursa (job #2543975) | Cod sursa (job #2421055) | Cod sursa (job #3276411) | Cod sursa (job #3225453)
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int,int>;
#define pb push_back
ifstream fin("scmax.in");
ofstream fout("scmax.out");
const int N = 1e5+3;
int n, v[N], prv[N], idx[N];
vector<int> dp;
int main()
{
fin.tie(0); fout.tie(0);
ios_base::sync_with_stdio(0);
fin >> n; for (int i = 1; i <= n; i++) fin >> v[i];
for (int i = 1; i <= n; i++){
int pos = lower_bound(dp.begin(), dp.end(), v[i]) - dp.begin();
if (pos == dp.size()) dp.pb(v[i]);
dp[pos] = v[i];
prv[i] = idx[pos-1];
idx[pos] = i;
}
fout << dp.size() << '\n';
stack<int> stk;
int k = idx[int(dp.size() - 1)];
while (k) { stk.push(v[k]); k = prv[k]; }
while (!stk.empty()) { fout << stk.top() << ' '; stk.pop(); }
return 0;
}
//17:13