Pagini recente » Cod sursa (job #1494972) | Cod sursa (job #2228925) | Cod sursa (job #2673310) | Cod sursa (job #1118565) | Cod sursa (job #2555779)
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
ifstream fin("scmax.in");
ofstream fout("scmax.out");
int inp[MAXN], best[MAXN], dp[MAXN], fat[MAXN], k, n;
bool compare(const int &x, const int &y)
{
return inp[x] < inp[y];
}
void read()
{
fin >> n;
for (int i = 1; i <= n; ++i)
fin >> inp[i];
}
void solve()
{
for (int i = 1; i <= n; ++i)
if (inp[i] > inp[dp[k]]) {
dp[++k] = i;
best[i] = k;
fat[i] = dp[k - 1];
}
else {
int ind = lower_bound(dp + 1, dp + k + 1, i, compare) - dp;
dp[ind] = i;
fat[i] = dp[ind - 1];
best[i] = ind;
}
}
void print(int ind)
{
if (ind == 0)
return;
print(fat[ind]);
fout << inp[ind] << ' ';
}
int main()
{
read();
solve();
fout << k << '\n';
print(dp[k]);
return 0;
}