Logo
(追記) (追記ここまで)

8100번 - Containers 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 128 MB1277100.000%

문제

We are given n containers, where 1 ≤ n ≤ 4. At the beginning all of them are full of water. The liter capacity of the i-th container is a natural number oi satisfying inequalities 1 ≤ oi ≤ 49.

Three kinds of moves can be made:

  • Pouring the whole content of one container into another. This move can be made unless there is too little room in the second container.
  • Filling up one container with part of the water from another one.
  • Pouring away the whole content of one container into a drain.

Write a program that:

  • reads form the standard input the number of containers n, the capacity of each container and the requested final amount of water in each container,
  • verifies, whether there exist a series of moves which leads to the requested final situation, and if there is one, the program computes the minimal number of moves leading to the requested situation,
  • writes the result into the standard output. The result should be the minimal number of moves leading to the requested final situation, or one word NIE (“no” in Polish) if there is no such a sequence of moves.

입력

In the first line of the standard input one positive integer n is written (n ≤ 4), this is the number of containers. There are n positive integers written in the second line. These are the capacities of the containers (the i-th integer oi denotes the capacity if the i-th container, 1 ≤ oi ≤ 49). In the third line of the input file there are written n numbers. These are the requested final volumes of water in the containers (the i-th integer wi denotes the requested final volume of water in the i-th container, 1 ≤ wi ≤ oi). 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.

제한

예제 입력 1

3
3 5 5
0 0 4

예제 출력 1

6

예제 입력 2

2
20 25
10 16

예제 출력 2

NIE

힌트

출처

Olympiad > Polish Olympiad in Informatics > POI 1995/1996 > Stage 1 2번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /