#C2053. Waste Distribution Problem

    ID: 45327 Type: Default 1000ms 256MiB

Waste Distribution Problem

Waste Distribution Problem

You are given a sequence of waste items, each characterized by its type and a corresponding volume. The waste types can be plastic, paper, metal, or glass. Additionally, you are given the maximum capacities for each bin: \(cp\) for plastic, \(cpy\) for paper, \(cm\) for metal, and \(cg\) for glass.

Your task is to process the list of waste items in the given order and assign each waste item's volume to its corresponding bin. If at any time the total volume in any bin exceeds its capacity, you should immediately output -1. Otherwise, after processing all items, output the total volume stored in each bin in the order: plastic, paper, metal, and glass.

Note: The input is read from stdin and the result should be printed to stdout.

inputFormat

The input is given in the following format:

n
waste_type_1 volume_1
waste_type_2 volume_2
... 
waste_type_n volume_n
cp cpy cm cg

Where:

  • n is the number of waste items.
  • Each of the next n lines contains a string and an integer representing the waste type and its volume.
  • The last line contains four integers representing the capacities of the plastic, paper, metal, and glass bins respectively.

outputFormat

If the distribution is valid (i.e. no bin exceeds its maximum capacity), output four integers representing the total volume in the plastic, paper, metal, and glass bins respectively, separated by spaces. If any bin exceeds its capacity at any point, output -1.

## sample
5
plastic 10
paper 15
metal 5
glass 20
paper 10
30 25 10 20
10 25 5 20