Cod sursa(job #3128927)
Utilizator | Data | 11 mai 2023 14:39:03 | |
---|---|---|---|
Problema | Subsir crescator maximal | Scor | 65 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.6 kb |
#include <bits/stdc++.h>
using namespace std;
const string FNAME = "scmax.";
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;
}