Given an empty glass, this glass has to be filled with water and the task is to find the maximum amount of water that the glass has held at any moment.
The program takes an input N denoting the number of steps.
Each step consists of two inputs T and X where T is the flag condition denoting whether the X ml of water has to be poured or drinked based on below conditions:
1. if T = 0, Pour X ml (millilitres) of water in the glass
2. if T = 1, Drink X ml of water from the glass
Input: N = 4, 0 1 0 1 0 1 1 3 Output: 3 Explanation: The glass initially has 0 ml of water. The maximum value is obtained after the first 3 operations. Input: N = 2 1 15 1 24 Output: 39
Approach THe approach can be simply put as adding up the volumes whenever T is 0 and finding the maximum of this volume.
- Even-odd turn game with two integers
- Speed of boat in still water from speed of stream and times taken
- Game of stones
- Python program for word guessing game
- C/C++ For loop with Examples
- Program to find the last digit of X in base Y
- 5 Best Programming Languages For Newbies
- Program to print the Ladder Pattern
- Program to print the Diagonals of a Matrix
- Minimum value to be assigned to the elements so that sum becomes greater than initial sum
- Find number of candidates in the Exam
- Program to Encrypt a String using ! and @
- Print the season name of the year based on the month number
- Program to duplicate Vowels in String
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.