Doubt of body builder question

Why is this wrong in this ques… Problem Code: BUILDB

#include<bits/stdc++.h>
#include
using namespace std;

int main()
{
int t,n,r,arr1[1000000],arr2[1000000],q,countmax=0,i=0;
cin>> t;

while(t--)
{
    countmax=0;
    cin >>n >> r;
    for(i=0;i<n;i++)
    {
        cin >>arr1[i];
    }
    //cin>>q;
    for(i=0;i<n;i++)
    {
        cin >>arr2[i];
    }

    for(i=1;i<n;i++)
    {
    countmax=(countmax-r)+arr2[i];
    }
    countmax=countmax+arr2[0];
    cout <<countmax <<endl;

    //cout <<"hi";
}

//cout <<"hi";
return 0;

}

I think you have failed to address a few corner cases:

  1. There might be cases in which tension may fall below 0
  2. Relax(R) is given /sec so you need to multiply it with arr1[i]-arr1[i-1]
  3. we are asked to print max tension but not final tension

Just try to figure out these issues, or else you can refer the code which I’ve submitted by modifying your original code.

https://www.codechef.com/viewsolution/45293248

1 Like

Thanks a lot…

in some cases your tension might be minus so just always take a max(0,tension given) each step more over take storage for max tension overall each time so to get max tension possible not the current tension