Skip to content

Commit 0e32461

Browse files
authored
Create Red_alert.c
1 parent 86a2f60 commit 0e32461

File tree

1 file changed

+97
-0
lines changed

1 file changed

+97
-0
lines changed

Codechef Problems/Red_alert.c

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
/* PROBLEM STATEMENT
2+
3+
4+
Finally a monsoon has come. According to the Meteorological Department, there will be rain in the upcoming N days in the city. Initially, the water level of the city is zero millimetres. The amount of rain on the i-th day can be described by an integer Ai as follows:
5+
6+
If Ai>0, the water level of the city increases by Ai millimetres on the i-th day.
7+
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.
8+
There will be a red alert in the city if the water level becomes strictly greater than H millimetres on at least one of the N days. Determine if there will be a red alert.
9+
10+
Input Format
11+
The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows.
12+
The first line of each test case contains three space-separated integers N, D and H.
13+
The second line contains N space-separated integers A1,A2,…,AN.
14+
Output Format
15+
For each test case, print a single line containing the string "YES" if there will be a red alert or "NO" otherwise.
16+
17+
Constraints
18+
1≤T≤103
19+
1≤N,D≤102
20+
0≤Ai≤102 for each valid i
21+
1≤H≤104
22+
Subtasks
23+
Subtask #1 (100 points): original constraints
24+
25+
Sample Input 1
26+
4
27+
4 2 6
28+
1 3 0 2
29+
2 1 100
30+
1 100
31+
4 2 3
32+
1 2 0 2
33+
3 7 10
34+
5 3 9
35+
Sample Output 1
36+
NO
37+
YES
38+
NO
39+
YES
40+
Explanation
41+
Example case 1:
42+
43+
On the first day, the water level of the city increases to 1 millimtre.
44+
On the second day, the water level increases by 3 millimeters and becomes 1+3=4 millimtres.
45+
On the third day, there is no rain in the city, so the water level decreases by D=2 millimtres and becomes 4−2=2 millimtres.
46+
On the fourth day, the water level increases by 2 millimtres and becomes 2+2=4 millimtres.
47+
There will be no red alert in the city because the water level does not exceed H=6 millimtres on any of the four days.
48+
49+
Example case 2: The water level of the city on the 2-nd day is equal to 101 millimtres, which is greater than H=100 millimtres, so there will be a red alert in the city.
50+
51+
Example case 3: The water levels of the city on the four days are [1,3,1,3]. The water level is equal to H=3 millimtres on the second and fourth day, but it does not exceed the threshold.
52+
53+
Example case 4: There will be a red alert in the city on the 3-rd day. */
54+
55+
// SOLUTION
56+
57+
#include <stdio.h>
58+
59+
int main(void) {
60+
61+
int t,n,d,h;
62+
63+
scanf("%d",&t);
64+
65+
while(t--)
66+
{
67+
scanf("%d %d %d",&n,&d,&h);
68+
int sum=0;int val; int ret=0;
69+
for(int i=0;i<n;i++)
70+
{
71+
scanf("%d",&val);
72+
if(val>0)
73+
{
74+
sum+=val;
75+
76+
}
77+
if(val==0)
78+
{
79+
sum=(sum<d)?0 : (sum-d);
80+
81+
}
82+
if(sum>h)
83+
{
84+
ret=1;
85+
}
86+
}
87+
if(ret==0)
88+
printf("NO\n");
89+
else
90+
printf("YES\n");
91+
92+
93+
}
94+
95+
96+
return 0;
97+
}

0 commit comments

Comments
 (0)