Sobes.tech
Intern — Senior

Calculation of the required number of barrels for complete pumping of sequential tanks

livecode

Task condition

Liquid tanks with non-negative volumes arrive on a conveyor belt (their order cannot be changed). There is an unlimited number of barrels of fixed positive volume into which this liquid must be poured. Each tank must be completely emptied: if there isn't enough space in the current barrel, a new barrel is used.

Given a sequence of tank volumes and the volume of a barrel, determine how many barrels are needed to empty all tanks.

Example: Tanks: 1 3 2 4 10 8 4 2 5 3 Barrel volume: 12