Pagini recente » Cod sursa (job #2279982) | Cod sursa (job #2279952) | Cod sursa (job #3308847) | Monitorul de evaluare | Cod sursa (job #2279964)
//
// main.cpp
// scmax
//
// Created by Darius Buhai on 10/11/2018.
// Copyright © 2018 Darius Buhai. All rights reserved.
//
/*
5|24 12 15 15 19
1 3 2 2 1
dp[i] = dp[i+1]
maximul de la j la n
ex2:
7 10 9 4 12 9 11 4 49 2 15
4 5 3 4 2 3 2 1 1 2 1
*/
#include <iostream>
#include <fstream>
#include <deque>
using namespace std;
ifstream fin("scmax.in");
ofstream fout("scmax.out");
int n, x, p[100001], s[100001];
deque<int> sec;
int CautareBinara(int x)
{
int l = 0, r = n;
while(l<=r)
{
int m = (l+r)/2;
if(s[m] == x)
return m;
if(s[m] > x)
r = m - 1;
if(s[m] < x)
l = m + 1;
}
return 0;
}
int main() {
int maxi = 0;
fin>>n>>x;
for(int i=0;i<n;i++)
{
fin>>x;
while(!sec.empty() && x<=sec.back())
sec.pop_back();
sec.push_back(x);
p[i] = (int)sec.size();
if(p[i]>maxi)
maxi = p[i];
}
fout<<maxi<<endl;
while(!sec.empty()){
fout<<sec.front()<<" ";
sec.pop_front();
}
return 0;
}