Cod sursa(job #3213281)

Utilizator leelcheeseCiovnicu Denis leelcheese Data 12 martie 2024 20:27:51
Problema Subsir crescator maximal Scor 55
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.87 kb
#include <bits/stdc++.h>
#include <unordered_map>
#define nmax 100006
#define MOD 1999999973
#define INF 2012345678
#define ll long long
using namespace std;
//#define fin cin
//#define fout cout

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

int n;
int a[nmax];
int dp[nmax], lg;

void CB(int x)
{
	if (dp[1] > x)
	{
		dp[1] = x;
		return;
	}
	if (dp[lg] < x)
	{
		dp[++lg] = x;
		return;
	}
	int st, dr, mij, p;
	st = 1; dr = lg; p = n + 1;
	while (st <= dr)
	{
		mij = (st + dr) / 2;
		if (dp[mij] > x)
		{
			p = mij;
			dr = mij - 1;
		}
		else
			st = mij + 1;
	}
	dp[p] = x;
}

int main()
{
	int i;
	fin >> n;
	for (i = 1; i <= n; i++)
		fin >> a[i];

	for (i = 1; i <= n; i++)
		CB(a[i]);

	fout << lg << "\n";
	for (i = 1; i <= lg; i++)
		fout << dp[i] << " ";

	fin.close();
	fout.close();
	return 0;
}