https://www.codechef.com/problems/REDALERT
submission link
#include
using namespace std;
#define ll long long
int main() {
long WL=0;long i=0;
ll T,N,D,H;
cin>>T;
while(T–)
{
cin>>N>>D>>H;
long A[N];
for(long i=0;i<N;i++)
{
cin>>A[i];
}
for(long j=0;j<N;j++)
{
if(A[j]>0)
WL+=A[j];
else {
if(A[j]==0)
{
if(WL>D)
WL-=D;
else
WL=0;
}
}
if(WL>H)
{
i=1;
break;
}
}
if(i==0)
cout<<"NO"<<endl;
else
cout<<"YES"<<endl;
}
return 0;
}
ssjgz
July 31, 2021, 6:31pm
2
Please either format your code or (better!) link to your submission - the forum software has mangled it and it won’t compile!
Edit:
Deciphered it; consider the test input:
2
2 1 5
3 3
1 1 2
1
1 Like
Okay wait …i am sharing the link of my submission @ssjgz
ssjgz
July 31, 2021, 6:43pm
4
1 Like
Can you please point out bug in my code?
ssjgz
July 31, 2021, 6:49pm
6
You’ve got a 100% reproducible testcase - please try and debug it yourself
I’ll wait 30 mins and provide a solution if you haven’t figured it out by then.
Edit:
Or not. Sigh.
1 Like
Your logic is completely correct. However, you have defined WL = 0 and i =0 outside the ‘while’ loop and you are not resetting them back to zero after printing the answer.
1 Like
You have to check the level of water i.e WL in your solution, at each iteration . Not only at the end.
submission link
Please see this and let me know my mistake…I am still unable to figure it out.
ssjgz
August 2, 2021, 4:21pm
10
@aryan_129 Beat me to it - see his comment, above
1 Like
Thank you! finally got it.