Pagini recente » Cod sursa (job #2026079) | Cod sursa (job #2127302) | Cod sursa (job #2095130) | Cod sursa (job #3032340) | Cod sursa (job #262104)
Cod sursa(job #262104)
#include <fstream>
using namespace std;
fstream f;
fstream g;
int vect[100000];
int ct[100000];
int i,j;
int n;
int main()
{
f.open("scmax.in",fstream::in);
f >> n;
for(i=0;i<n;i++)
f >> vect[i];
f.close();
g.open("scmax.out",fstream::out);
int max[2];
max[0]=1;
ct[n-1]=1;
for(i=n-2;i>=0;i--)
{if(vect[i]<vect[i+1])
ct[i]=ct[i+1]+1;
else
for(j=i+1;j<n;j++)
if(vect[i]<=vect[j]){
ct[i]=ct[j]+1;
break;
}
else
ct[i]=ct[j];
if(!ct[i])
ct[i]=1;
if(ct[i]>max[0])
{
max[0] = ct[i];
max[1] = i;
}
}
g << max[0] << "\n";
for(i=max[1];i<n;i++)
if(max[0] == ct[i])
{
g << vect[i] << " ";
max[0]--;
}
g.close();
return 0;
}