TABLESUM WA

Could someone please tell me what’s going wrong with this TABLESUM code? I am getting WA in all except 3 test cases. The algorithm is O(N), so time is not an issue.

https://www.dropbox.com/s/im7sjck0z8elukk/TABLESUM.cpp?dl=0

1 Like

I already saw that thread, in fact my solution is same as the O(N) solution in the Stack Overflow link, but yet my code yields WA. Thanks anyway

YEAH SOMEBODY PLEASE RESPOND … I’m also having the same problem … http://cpp.sh/2jym … THANKS IN ADVANCE!!!

#include
#include<math.h>
#include<stdio.h>
using namespace std;
int a[200005],n,large[200005],front[200005];
int main()
{
//freopen(“question.txt”,“r”,stdin);
cin>>n;
int i,j,k;
for(i=0;i<n;i++)cin>>a[i];
large[n-1]=a[n-1]+1;
for(i=n-2;i>=0;i–)large[i]=max(large[i+1]+1,a[i]+1);
//for(i=0;i<n;i++)cout<<large[i]<<" “;cout<<endl;
front[0]=a[0]+1;
for(i=1;i<n;i++)front[i]=max(front[i-1],a[i]+i+1);
//for(i=0;i<n;i++)cout<<front[i]<<” “;cout<<endl;
cout<<front[n-1]<<” “;
for(i=1;i<n;i++)
{
j=front[n-1-i]+i;j=max(j,large[n-i]);
cout<<j<<” ";
}
}