Water Tank & Buckets TCS NQT

Water Tank & Buckets TCS NQT 

Problem:

There is a water tank with the maximum capacity of X litres and a bucket with the maximum capacity of Y litres. A boy wants to fill greater than or equal to 80% of the water tank with the water using the bucket. The amount of water taken at a time in the bucket is not fixed as it can be any value less than or equal to Y. The program must accept the values of X, Y and a list of integers representing the amount of water taken in the buckets to fill the water tank. The program must print the number of buckets B poured into the water tank to reach greater than or equal to 80% of water. If it is not possible to fill 80% of the water tank, the program must print the string value "TANK NOT FULL" as the output. 

Boundary Condition(s): 

1 <= Y <= X <= 1000 

Input Format: 

The first line contains X. The second line contains Y. The line(s), each contains an integer representing the amount of water taken in the bucket. 

Output Format: 

The first line contains B or the string value "TANK NOT FULL". 

Example Input/Output 1: 

Input: 

100 20 20 15 10 20 20 20 

Output: 

Explanation: 

Here the maximum capacity of a tank is 100 litres and the maximum capacity of a bucket is 20 litres. The amount of water taken in the buckets to fill the water tank are 20, 15, 10, 20, 20 and 20. After pouring the first 5 buckets of water into the tank. The tank contains 85 (20+15+10+20+20) litres of water which is greater than 80% of its capacity. Hence the output is 5. 

Example Input/Output 2: 

Input: 

150 50 10 20 50 10 10 

Output: 

TANK NOT FULL 

Example Input/Output 3: 

Input: 

100 10 10 10 10 10 10 10 10 10 

Output: 

8

Program:

x = int(input()) 

y = int(input()) 

tot = 0

count = 0 

while 1:

    try: 

        water = int(input())

        tot += water 

        count += 1 

        if tot/x >= 0.8:

            print(count)

            break

    except:

        if tot/x >= 0.8:

            print(count)

        else:

            print("TANK NOT FULL")

        break

Comments

Popular posts from this blog

Pronic Integers in N - InfyTQ question

Count Strong Points - Accenture

Letters at position of multiples of a number