Mai intai trebuie sa te autentifici.
Cod sursa(job #262104)
| Utilizator | Data | 18 februarie 2009 23:21:32 | |
|---|---|---|---|
| Problema | Subsir crescator maximal | Scor | 10 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 1.02 kb |
#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;
}
