Pagini recente » Monitorul de evaluare | Monitorul de evaluare | Monitorul de evaluare | Cod sursa (job #3364521) | Cod sursa (job #3364519)
/******************************************************************************
Online C++ Compiler.
Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.
*******************************************************************************/
#include <fstream>
using namespace std;
ifstream f("scmax.in");
ofstream g("scmax.out");
long long n, mx, dp[100000], m[100000], sir[100000], pozx, z;
int main()
{
f>>n;
for(int i=0; i<n; i++){
f>>m[i];
for(int j=i-1; j>=0; j--)
if(m[j] < m[i])
dp[i] = max(dp[i], dp[j]);
dp[i]++;
if(dp[i] > mx){
mx = dp[i];
pozx = i;
}
}
g<<mx<<'\n';
sir[0] = m[pozx];
for(z=1; z<mx; z++){
sir[z] = 2000000000;
for(int i=pozx-1; i>=0; i--)
if(dp[i] == mx-z && sir[z-1] > m[i]){
sir[z] = min(sir[z], m[i]);
pozx = i;
}
}
for(int i=z-1; i>=0; i--)
g<<sir[i]<<' ';
return 0;
}