Pagini recente » Cod sursa (job #863223) | Cod sursa (job #137521) | Cod sursa (job #2388994) | Cod sursa (job #2506761) | Cod sursa (job #3128926)
#include <bits/stdc++.h>
using namespace std;
const string FNAME = "data.";
ifstream fin(FNAME + "in");
ofstream fout(FNAME + "out");
int main() {
int n;
fin >> n;
int x;
fin >> x;
vector<int> dp = {x};
for (int i = 1; i < n; i++) {
fin >> x;
auto it = lower_bound(dp.begin(), dp.end(), x);
if (it == dp.end()) {
dp.push_back(x);
} else {
*it = x;
}
}
fout << dp.size() << '\n';
for (int it : dp) {
fout << it << ' ';
}
fout << endl;
fout.close();
return 0;
}