Sobes.tech
Junior — Middle+

Finding the smallest volume of tanks for complete casting of all vessels

livecode

Task condition

Given a sequence of non-negative volumes of vessels containing liquid, and a known number of tanks. The task is to calculate the minimum volume of each tank so that all vessels can be fully poured into the tanks, following these rules:

  • The vessels are poured sequentially, in the same order they are given.
  • Each vessel must be poured completely.
  • If the current vessel does not fit into the partially filled tank, the next empty tank is used.

Example: Suppose there are 4 tanks and vessels with volumes: 1 3 2 4 10 8 4 2 5 3. It is sufficient to make the tanks with a volume of 12 liters, then the pouring can be done as follows: 1 3 2 4 | 10 | 8 4 | 2 5 3.