Pagini recente » Cod sursa (job #2422978) | Cod sursa (job #319433) | Cod sursa (job #617748) | Cod sursa (job #2278877) | Cod sursa (job #1338650)
#include <fstream>
#define NMAX 100004
using namespace std;
ifstream fin("scmax.in");
ofstream fout("scmax.out");
int n;
int a[NMAX];
int best[NMAX];
int poz[NMAX];
int pb, nr;
void init();
void scm();
void afisare();
int main(){
init();
scm();
afisare();
return 0;
}
void init(){
fin>>n;
int i;
for(i = 1; i<= n; ++i) fin>>a[i];
}
void scm(){
int i,aux;
pb = 1;
best[1] = a[1];
poz[1] = 1;
for(i = 2; i<= n; ++i){
if(a[i] > best[pb]){
best[++pb] = a[i];
poz[i] = pb;
} else if( a[i] < best[pb]){
aux = pb;
while(a[i] < best[aux])aux--;
++aux;
best[aux] = a[i];
poz[i] = aux;
}
}
}
void afisare(){
int i;
nr = poz[1];
for(i = 2; i<= n; ++i)
nr = max( poz[i], nr );
fout<<nr<<'\n';
for(i = 1; i< pb ; ++i) fout<<best[i]<<' ';
fout<<best[i]<<'\n';
}