Pagini recente » Cod sursa (job #1282563) | Cod sursa (job #2483733) | Cod sursa (job #1874008) | Cod sursa (job #800981) | Cod sursa (job #2700538)
#include <bits/stdc++.h>
#define ll long long
#define sz(x) (int)(x).size()
#define debug(v,n) for (int i = 1; i <= (n); ++i) cout << v[i] << " ";
#define next cout << '\n'
using namespace std;
const int N = 100005;
int n, v[N], maxx = 1, posMax = n;
set<int> ord;
int main() {
//ifstream fin("date.in.txt");
ifstream fin("scmax.in");
ofstream fout("scmax.out");
fin >> n;
for (int i = 1; i <= n; ++i)
fin >> v[i];
ord.insert(v[n]);
for (int i = n - 1; i >= 1; --i) {
//cout << i << " " << distance(ord.upper_bound(v[i]), ord.end()) << '\n';
if(distance(ord.upper_bound(v[i]), ord.end()) > maxx) {
posMax = i;
maxx = distance(ord.upper_bound(v[i]), ord.end()) ;
}
ord.insert(v[i]);
}
set<int> ans;
for (int i = posMax; i <= n; ++i) {
if(v[posMax] <= v[i])
ans.insert(v[i]);
}
fout << maxx + 1 << '\n';
for (int x : ans)
fout << x << " ";
return 0;
}