Pagini recente » Cod sursa (job #1472922) | Cod sursa (job #2366972) | Cod sursa (job #2253892) | Cod sursa (job #2875838) | Cod sursa (job #1454587)
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
ifstream f("scmax.in");
ofstream g("scmax.out");
int n;
f >> n;
vector<long long> v(n), capate_segmente(n+1, 2000000001), pt_ce_e_capat(n);
for(int i = 0; i < n; ++i){
f >> v[i];
auto it = lower_bound(begin(capate_segmente), end(capate_segmente), v[i]);
*it = v[i];
pt_ce_e_capat[i] = distance(begin(capate_segmente), it); }
auto it = lower_bound(begin(capate_segmente), end(capate_segmente), 2000000001);
const int lungime_rez = distance(begin(capate_segmente), it);
g << lungime_rez << '\n';
vector<long long> rez(lungime_rez);
for(int i = n-1, lung_cur = lungime_rez; i >= 0 && lung_cur > 0; --i){
if(pt_ce_e_capat[i] == lung_cur-1){
--lung_cur;
rez[lung_cur] = v[i]; } }
for(const auto x : rez){
g << x << ' '; }
return 0; }