Pagini recente » Statistici Dumitrescu Florin (Florin090503) | Algoritmiada 2009 - Clasament Runda 1, Clasele 9-10 | Cod sursa (job #1296499) | Cod sursa (job #2631844) | Cod sursa (job #2967556)
/*
Lefter Sergiu - 19/01/2023
*/
#include <fstream>
using namespace std;
ifstream in("scmax.in");
ofstream out("scmax.out");
const int N = 100000;
int n, pmax = 1, a[N + 1], lung[N + 1];
void refacSubsirul(int p, int val, int l) {
if (l == 1) {
return;
}
if (a[p] < val && lung[p] == l - 1) {
refacSubsirul(p - 1, a[p], lung[p]);
}
else {
refacSubsirul(p - 1, val, l);
}
}
int main() {
in >> n;
for (int i = 1; i <= n; ++i) {
in >> a[i];
int lJ = 0;
for (int j = 1; j < i; ++j) {
if (a[j] < a[i]) {
lJ = max(lJ, lung[j]);
}
}
lung[i] = 1 + lJ;
if (lung[i] > lung[pmax]) {
pmax = i;
}
}
out << lung[pmax] << '\n';
refacSubsirul(pmax, a[pmax] + 1, lung[pmax] + 1);
in.close();
out.close();
return 0;
}