Runtime error in LELEMONADE

i tried to build a faster solution but getting sigsegv can anyone help.

thanks in advance!!

my solution: CodeChef: Practical coding for everyone

problem link: LELEMON Problem - CodeChef

  1. The problem is in the loop

for(j=0;j< m;j++)

{

if(a[j]>=p[j])

netsum+=sum[j];

else

{

for(int y=p[j]-1;y>=p[j]-a[j];y--)<Br>
netsum+=botal[j][y];<Br>
}<Br>

}

Here m is in the range 1<=m<=10000 and the size of a[] and p[] are 102,101 respectively.

When j becomes greater than or equal to size of arrays,i.e.,j>=size, it causes runtime error.


THE CORRECTION:

for(j=0;j<101;j++)<Br>

{

if(a[j]>0)

{

  if(a[j]>=p[j])

  netsum+=sum[j];<Br>
   else<Br>
   {<Br>
    for(int y=p[j]-1;y>=p[j]-a[j];y--)<Br>
    netsum+=botal[j][y];<Br>
   }<Br>
 }<BR>
}
  1. Also, you are trying to build a faster solution, so use scanf/printf instead of cin/cout. If you want to use cin/cout read the following discussion on fast i/o.

    Enormous input test C++
1 Like