def main():
t = int(input())
while t > 0:
n, d, h = map(int, input().split())
a = list(map(int, input().split()))
count = 0
for i in range(len(a)):
if a[i] > 0:
count += a[i]
elif a[i] == 0:
count -= d
if count > h:
print(“Yes”)
else:
print(“NO”)
t -= 1

if name == ‘main’:
main()

Please tell me what’s wrong with this code!

`elif a[i] == 0: count -= d`

This step is wrong because the level of water at any day can’t be negative. You have to handle it using count = max(0, count-d).

could you please explain me this logic behind count = max(0, count-d)?

It’s given in the question:

If Ai=0, there is no rain on the i-th day. The water level of the city decreases by D millimetres on such a day. However, if the water level is less than D millimetres before the i-th day, then it becomes zero instead.

i corrected my code with your provided solution but still its not getting accepted even in the practice section , could you please help me with that??

I saw your recent code. Actually, you have to check for every day and you are just checking for the last day. This can be done by using a boolean variable, at any moment if count > h, then you have found the day with red alert and can break the loop.

I modified your code a bit (It is passing all the test cases now)

``````# cook your dish here
def main():
t = int(input())
while t > 0:
n, d, h = map(int, input().split())
a = list(map(int, input().split()))
count = 0
f = False
for i in range(len(a)):
if a[i] > 0:
count += a[i]
elif a[i] == 0:
count = max(0, count-d)

if(count > h):
f = True
break

if(f):
print("Yes")
else:
print("NO")
t -= 1

if __name__ == '__main__':
main()
``````

thankyou soo much for helping me out here, i understood the problem!!