Pagini recente » Cod sursa (job #2185792) | Cod sursa (job #1782876) | Cod sursa (job #100856) | Cod sursa (job #1951333) | Cod sursa (job #262085)
Cod sursa(job #262085)
#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);
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
if(j==n-1)
ct[i]=1;
else
ct[i]=ct[j];
int max=0;
for(i=0;i<n;i++)
if(ct[i]>max)
max = ct[i];
g << max << "\n";
for(i=0;i<n;i++)
if(max == ct[i])
{
g << vect[i] << " ";
max--;
}
g.close();
return 0;
}