Pagini recente » Cod sursa (job #198160) | Cod sursa (job #300149) | Cod sursa (job #1193678) | Cod sursa (job #928228) | Cod sursa (job #1222408)
/*
subsir crescator maximal infoarena
*/
#include<vector>
#include<string>
#include<string.h>
#include<algorithm>
#include<cstdio>
#include<fstream>
#include<iostream>
#include<ctime>
#include<set>
#include<map>
#include<cmath>
using namespace std;
#define LL long long
#define PII pair<int ,int>
#define PCI pair<char ,int>
#define VB vector <bool>
#define VI vector <int>
#define VC vector <char>
#define WI vector<VI>
#define WC vector<VC>
#define RS resize
#define X first
#define Y second
#define FORN(i,n) for(int i=0;i<n;++i)
#define FOR(i,a,b) for(int i=a;i<=b;++i)
#define FORD(i,a,b) for(int i=a;i>=b;--i)
#define REPEAT do
#define UNTIL(x) while((x))
#define IN_FILE "scmax.in"
#define OUT_FILE "scmax.out"
ifstream f(IN_FILE);
ofstream g(OUT_FILE);
//variables
VI a, b;
int n,lenghtMax,posLenghtMax;
//other functions
string genereareSir(int lenght, int pos)
{
FORD(i, pos - 1, 0)
{
if (a[i] < a[pos] && b[i] == lenght - 1)
{
if (lenght == 2)
{
return to_string(a[i]);
}
return genereareSir(lenght - 1, i) + " " + to_string(a[i]);
}
}
return "";
}
void reading()
{
f >> n;
a.RS(n);
b.RS(n);
FORN(i, n)
{
f >> a[i];
}
f.close();
}
void solving()
{
FORN(i, n)
{
int maxiForAPos = 1;
FORN(j, i)
{
if (a[i] > a[j])
{
if (b[j] >= maxiForAPos)
{
maxiForAPos = b[j] + 1;
}
}
}
b[i] = maxiForAPos;
if (maxiForAPos > lenghtMax)
{
lenghtMax = maxiForAPos;
posLenghtMax = i;
}
}
}
void write_data()
{
g << lenghtMax<<"\n";
g << genereareSir(lenghtMax, posLenghtMax)+" "+to_string(a[posLenghtMax]);
}
int main()
{
reading();
solving();
write_data();
}