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 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 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()