Feedback | If you notice incorrect translations in Contester, please let author know.
|
|
Time limit 2000/4000/4000/4000 ms. Memory limit 65000/65000/65000/65000 Kb. Question by Ibrahim Mesecan.
Olive Containers
You work in an olive oil factory. People bring olives
with different amounts and you put olives to the
containers. You can pour olive brought by a farmer to the
first container where all the olive fit. If all the olive
cannot be poured into this container,
you try to pour it to the next container. If there is
not enough space in any container the olive is not
taken.
Question:
Write a program that is going to read the capacities
of m containers and n olive bottles brought by farmers.
Then, show 1) Amount of olive which is not
taken and 2) The total empty space in the containers.
Input specification
In the first line, you will be given two integers: The
number of olive bottles brought by farmers (n)
and the number of containers (m) in the factory
where 0 ≤ m ≤ 200 and 1 ≤ n ≤ 2000.
Then, in the following line, you will be given m integers,
the capacities of m containers. The last line contains
n integers amount of olives brought by farmers
where the container capacities and olive amounts
are integers between 0 and 10,000.
Output specification:
Show two information: 1) Amount of olive which is not
taken and 2) The total empty space in the containers.
Sample Input I
5 2
10 12
6 7 3 4 5
|
Sample Output I
5 2
|
Explanation:
There are 5 olive bottles brought by farmers,
and two containers with the capacities: 10 and 12 liters.
- The first olive bottle (6 liters) is poured to the
first container.
- The second olive bottle (7 liters) doesn't fit into the first
container and it is poured into the second container
- The third bottle is poured into the first container.
Then now, the first container has 9 liters.
- The fourth bottle is poured into the second container.
Then now, the second container has 11 liters.
- There is not enough space in any container for the last
bottle. So, it's not taken
Then, totally 5 liters olive is not taken. And, the containers
contain 9 and 11 liters of milk. So, there is two liters
space in two containers.
Для отправки решений необходимо выполнить вход.
|