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
- Program to print the given digit in words
- Print the Alphabets A to Z in Star Pattern
- How can we write main as a class in C++?
- Types of Errors in Java with Examples
- Minimum distance from a point to the line segment using Vectors
- Array formed from difference of each element from the largest element in the given array
- Empty an Array by removing maximum of K value from it
- Program to find the Product of diagonal elements of a matrix
- The "Hello World" To Programming
- Program to calculate Percentile of Students
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. 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.