Cod sursa(job #3128926)
| Utilizator | Data | 11 mai 2023 14:37:50 | |
|---|---|---|---|
| Problema | Subsir crescator maximal | Scor | 0 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.6 kb |
#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;
}
