Cod sursa(job #1582798)
Utilizator | Data | 28 ianuarie 2016 15:07:35 | |
---|---|---|---|
Problema | Subsir crescator maximal | Scor | 0 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.95 kb |
#include <iostream>
#include <fstream>
using namespace std;
int n, i, v[100000], ok, lmax = -1, pozM, l, poz;
ifstream in("scmax.in");
ofstream out("scmax.out");
int main()
{
int j;
in>>n;
for(i=0;i<n;i++){
in>>v[i];
}
for(i=0;i<n;i++){
j = i + 1;
l=0;ok = 0;
while(ok == 0 && j < n){
if(v[j] >= v[j+1]){
l++;
}else{
ok = 1;
}
if(lmax == -1 || pozM == i){
lmax++;
pozM = i;
}else{
if(l> lmax){
pozM = i;
lmax = l;
}
}
j++;
}
}
int lungime = 1;
for(i=pozM;i<n-1;i++){
if(v[i] != v[i+1])
lungime++;
}
out<<lungime<<endl;
for(i=pozM;i<n;i++){
if(v[i] != v[i+1])
out<<v[i]<<" ";
}
}