Pagini recente » Cod sursa (job #2440550) | Cod sursa (job #2104062) | Cod sursa (job #2728533) | Cod sursa (job #356748) | Cod sursa (job #2240171)
#include <cstdio>
FILE *fin = freopen("subsir2.in","r",stdin); FILE *fout = freopen("subsir2.out","w",stdout);
static const int NMAX = 5e3 + 5;
/* ---------- Data -------- */
int n, first;
int v[NMAX], best[NMAX], next[NMAX];
/* ---------- Data -------- */
void ReadInput()
{
scanf("%d",&n);
for(int i = 1; i<= n; ++i)
scanf("%d",&v[i]);
}
void Solve()
{
int mini = 1e6+5, maxi =0;
best[n] = 1;
next[n] = 0;
for(int i = n-1; i>= 1; i--)
{
best[i] = 1;
next[i] = i;
mini = 1e6+5;
for(int j = i + 1; j<= n ; ++j)
{
if(v[j] > v[i])
{
if(v[j] < mini){
mini = v[j];
best[i] = best[j]+1;
next[i] = j;
}
}
}
if(best[i] >= maxi)
{
maxi = best[i];
first = i;
}
}
return;
}
void PrintOutput()
{
printf("%d\n",best[1]);
int x = next[first];
printf("%d ",first);
while(x)
{
printf("%d ",x);
x = next[x];
}
return;
}
int main()
{
ReadInput();
Solve();
PrintOutput();
}