W razie problemów technicznych ze Szkopułem, prosimy o kontakt mailowy pod adresem [email protected].
Jeśli chciałbyś porozmawiać o zadaniach, rozwiązaniach lub problemach technicznych, zapraszamy na serwery Discord. Są one moderowane przez społeczność, ale członkowie zespołu technicznego też są tam aktywni.
We are given containers, where . At the beginning all of them are full of water. The liter capacity of the -th container is a natural number satisfying inequalities .
Three kinds of moves can be made:
Write a program that:
In the first line of the standard input one positive integer is written (), this is the number of containers. There are positive integers written in the second line. These are the capacities of the containers (the -th integer denotes the capacity if the -th container, ). In the third line of the input file there are written numbers. These are the requested final volumes of water in the containers (the -th integer denotes the requested final volume of water in the -th container, ). All integers in the second and the third line are separated by single spaces.
If it is not possible to result in requested final situation making only allowed moves, your program should write only one word NIE to the standard output, otherwise only one integer equal to the minimal number of moves which lead to the requested final situation should be written.
For the input data:
3 3 5 5 0 0 4
the correct result is:
6
whereas for the input data:
2 20 25 10 16
the correct output is:
NIE
Task author: Piotr Chrzastowski-Wachtel.