Cod sursa(job #2662449)

Utilizator CyborgSquirrelJardan Andrei CyborgSquirrel Data 24 octombrie 2020 09:38:40
Problema Subsir crescator maximal Scor 10
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.69 kb
#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>

using namespace std;

ifstream fin("scmax.in");
ofstream fout("scmax.out");

int n;
int v[100041];
vector<int> w = {0};

int bs(int a){
	int lt = 0, rt = w.size();
	while(lt < rt){
		int m = (lt+rt)/2;
		if(v[w[m]] >= a){
			rt = m-1;
		}else{
			lt = m+1;
		}
	}
	return lt+1;
}

int main(){
	// ios_base::sync_with_stdio(false);
	fin >> n;
	for(int i = 1; i <= n; ++i){
		fin >> v[i];
		int p = bs(v[i]);
		if(p > w.size()){
			w.push_back(i);
		}else{
			w[p] = i;
		}
	}
	fout << w.size()-1 << "\n";
	for(int i = 1; i < w.size(); ++i){
		fout << v[w[i]] << " ";
	}
	return 0;
}