Pagini recente » Cod sursa (job #2401287) | Cod sursa (job #2890724) | Cod sursa (job #2600954) | Cod sursa (job #418919) | Cod sursa (job #2800993)
/* [A][M][C][B][N] / [K][R][I][P][6][8] */
#include <bits/stdc++.h>
using namespace std;
const char sp = ' ', nl = '\n';
const int MOD = 10007;
ifstream fin("scmax.in");
ofstream fout("scmax.out");
int n, last[100005], len = 1;
int bs(int x) {
int st = 0, dr = len + 1;
while (dr - st > 1) {
int mid = st + (dr - st) / 2;
if (last[mid] > x)
dr = mid;
else
st = mid;
}
return dr;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
fin >> n >> last[1];
for (int i = 2, x; i <= n; ++i) {
fin >> x;
if (last[len] < x)
last[++len] = x;
else
last[bs(x)] = x;
}
fout << len << nl;
for (int i = 1; i <= len; ++i)
fout << last[i] << sp;
}