Cod sursa(job #3135837)
| Utilizator | Data | 4 iunie 2023 15:48:10 | |
|---|---|---|---|
| Problema | Subsir crescator maximal | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.61 kb |
#include <iostream>
#include <fstream>
using namespace std;
#define MAXN 100010
ifstream f("scmax.in");
ofstream g("scmax.out");
int n, v[MAXN], tata[MAXN], maxim, dp[MAXN], poz[MAXN], j;
void afis(int nod) {
if (nod == 0) {
return;
}
afis(tata[nod]);
g << v[nod] << ' ';
}
int main() {
f >> n;
for (int i = 1; i <= n; ++i) {
f >> v[i];
j = 1;
while (dp[j] < v[i] && j <= maxim) {
++j;
}
dp[j] = v[i];
poz[j] = i;
tata[i] = poz[j - 1];
maxim = max(maxim, j);
}
g << maxim << '\n';
afis(poz[maxim]);
}
