Hello, everyone… I was unable to solve the Lunchtime July Problem REDALERT. This is my code.
#include <iostream>
using namespace std;
int main() {
int t(0), water(0);
cin >> t;
while (t--)
{
int n;
cin >> n;
int d, h;
cin >> d >> h;
for (int i = 0; i < n; i++)
{
int x(0);
cin >> x;
if (x > 0) { water = water + x; }
else if (water > d && x == 0) { water = water - d; }
else if (water == 0 || water <= d) { water = 0; }
if (water > h)
{
cout << "YES" << endl;
water = 0, h=-1;
break;
}
}
if (water <= h)
{
cout << "NO" << endl;
water = 0;
}
}
}
I know the h = -1 is bad in the if loop. I have seen the editorial and will try to implement flag in my code, but for the life of me I can’t figure out why is it giving WA. @soumyadeep_21 Could you please provide the second test case. I would like to try to solve the question on my own. The test case will greatly help me, Thank You.