Cod sursa(job #2977393)

Utilizator bogdann31Nicolaev Bogdan bogdann31 Data 11 februarie 2023 15:26:00
Problema Subsir crescator maximal Scor 70
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.99 kb
#include <bits/stdc++.h>
using namespace std;
#define mod                1000000007
#define ll                 long long 
#define all(v)             v.begin(), v.end()
#define fr(n)              for(ll i=0;i<n;++i)
#define ctz(x)             __builtin_ctzll(x)
#define clz(x)             __builtin_clzll(x)
#define pcount(x)          __builtin_popcountll(x)
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};


class InParser {
private:
	FILE *fin;
	char *buff;
	int sp;
 
	char read_ch() {
		++sp;
		if (sp == 4096) {
			sp = 0;
			fread(buff, 1, 4096, fin);
		}
		return buff[sp];
	}
 
public:
	InParser(const char* nume) {
		fin = fopen(nume, "r");
		buff = new char[4096]();
		sp = 4095;
	}
	
	InParser& operator >> (int &n) {
		char c;
		while (!isdigit(c = read_ch()) && c != '-');
		int sgn = 1;
		if (c == '-') {
			n = 0;
			sgn = -1;
		} else {
			n = c - '0';
		}
		while (isdigit(c = read_ch())) {
			n = 10 * n + c - '0';
		}
		n *= sgn;
		return *this;
	}
	
	InParser& operator >> (long long &n) {
		char c;
		n = 0;
		while (!isdigit(c = read_ch()) && c != '-');
		long long sgn = 1;
		if (c == '-') {
			n = 0;
			sgn = -1;
		} else {
			n = c - '0';
		}
		while (isdigit(c = read_ch())) {
			n = 10 * n + c - '0';
		}
		n *= sgn;
		return *this;
	}
};




 #define cin fin
 #define cout fout
InParser fin("scmax.in");
 ofstream fout("scmax.out");
 
 

void solve(){
    ll n;cin>>n;
    ll a[n+1];
    a[0]=0;
    for(ll i=1; i<=n; i++){
    	cin>>a[i];
	}
	vector<ll> dp(n+1, 0);
	ll temp=0;
	for(ll i=1; i<=n;i++){
		for(ll j=i-1; j>=0;j--){
			if(a[j]<a[i]) dp[i]=max(dp[i], dp[j]+1);
		}
		temp=max(temp, dp[i]);
	}
	cout<<temp<<"\n";
	ll cnt=INT_MAX;
	vector<ll> v;
	for(ll i=n; i>0; i--){
		if(dp[i]==temp  && a[i]<cnt){
		  //  cout<<a[i]<<" ";
		    v.push_back(a[i]);
		    cnt=a[i];
		    temp--;
		}
	}
	reverse(all(v));
	fr(v.size()){
	    cout<<v[i]<<" ";
	}
	
}
 
 
int main(){
//   ios_base::sync_with_stdio(false); cin.tie(NULL);
//   ll t;cin>>t;while(t--){solve();cout<<endl;}
	solve();
}