Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*. Southwest monsoon arrived in Andhra Pradesh. The Indian Meteorological Department (IMD)
- announced that there will be heavy rains in the upcoming “N” days in Vadlamudi area.
- Initially, the Vadlamudi area has ‘zero’ millimeters as its water level. The amount of rain on
- the i-th day can be described by an integer “Ri” as follows:
- If Ri > 0, the water level of Vadlamudi area increases by Ri millimeters on the i-th day.
- If Ri = 0, there is no rain on the i-th day. The water level decreases by “X” millimeters on
- such a day. Though, if the water level is less than X millimeters before the i-th day, then it
- becomes zero.
- There will be a high alert in Vadlamudi area if the water level becomes greater
- than “G” millimetres on at least one of the “N” days. Decide if there will be a High Alert?
- Input
- The first line of the input contains a single integer T denoting the number of test cases.
- The first line of each test case contains three space-separated integers N, X and G.
- The second line contains N space-separated integers R1, R2, R3……….RN
- Output: For each test case, print - "YES" if there will be a high alert or "NO" otherwise.*/
- /* INPUT
- 3
- 4 2 6
- 1 3 0 2
- 2 1 100
- 1 100
- 4 2 3
- 1 2 0 2
- OUTPUT
- No
- Yes
- No*/
- #include<stdio.h>
- #include<stdlib.h>
- int main()
- { int test_case,n,x,g,i;
- int rain[30],water_level,flag;
- printf("Enter number of test cases: \n");
- scanf("%d",&test_case);
- while(test_case)
- {
- start: //jump level for goto
- if(test_case == 0)
- break;
- test_case--;
- water_level = 0;
- flag = 0;
- printf("\nEnter value of 'N','X' & 'G' according to question: ");
- scanf("%d %d %d",&n,&x,&g);
- printf("\nPlease enter amount of rain of all %d days: ",n);
- for(i=0;i<n;i++)
- {
- printf("Enter rain amount for day %d: ",i+1);
- scanf("%d",&rain[i]);
- if(rain[i]!=0) //if rain amount is non-zero it mean water-level will increse
- water_level = water_level + rain[i];
- else
- {
- if(x > water_level)//if water-level less than 'X' then it will become zero
- water_level = 0;
- else
- water_level = water_level - x;
- }
- if(water_level > g)//checking for high alert
- {
- printf("\nYES");
- flag++;
- break;
- }
- }
- if(flag == 0)
- printf("\nNO");
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement