problem statement is here
#include<stdio.h>
int main(){
long a,b,c,d,i,j,t,n;
scanf("%ld",&t);
long ar[100005],br[100005],cr[100005]={0};
for(i=0;i<t;i++){
scanf("%ld",&ar[i]);
}
j=0;
br[j]=t;
j++;
a=1;
for(i=t-2;i>=0;i--){
if(ar[i]==a){
br[j++]=i;
cr[i]=1;
}else if(cr[i+ar[i]+1]==1){
br[j++]=i;
cr[i]++;
}
a++;
}
for(i=j-1;i>=0;i--){
if(br[i]!=0)
printf("%ld\n",br[i]);
}
return 0;
}
No comments:
Post a Comment