Bank Notes

View as PDF

Submit solution

Points: 7
Time limit: 0.6s
Memory limit: 64M

Problem type
Allowed languages
Ada, Assembly, Awk, Brain****, C, C#, C++, COBOL, CommonLisp, D, Dart, F#, Forth, Fortran, Go, Groovy, Haskell, Intercal, Java, JS, Kotlin, Lisp, Lua, Nim, ObjC, OCaml, Octave, Pascal, Perl, PHP, Pike, Prolog, Python, Racket, Ruby, Rust, Scala, Scheme, Sed, Swift, TCL, Text, Turing, VB, Zig

Note: This problem is an easier version of the POI problem Bank Notes from 2005.

The Byteotian Bit Bank (BBB) has the largest network of cash dispensers in the whole Byteotia. The BBB have decided to improve their dispensers and have asked you for help. The legal tender in Byteotia are bank notes of denominations b_1, \dots, b_n. The BBB have concluded that the cash dispensers are to pay every sum in the smallest possible total number of notes.


Write a programme that:

  • reads from the standard input the description of the dispenser's notes stock and the sum to be paid off,
  • determines the minimal total number of bank notes sufficient to pay the desired sum off,
  • writes the result to the standard output.


In the first line of the standard input the number of denominations is written n, 1 \le n \le 200. The second line contains n integers b_1, b_2, \dots, b_n, (1 \le b_i \le 20\,000), separated by a single space. The third line contains n integers c_1, c_2, \dots, c_n, (1 \le c_i \le 20\,000), also separated by a single space; c_i is the number of banknotes of denomination b_i left in the cash dispenser. In the last, fourth line of input there is one integer k - the sum to be paid off, (1 \le k \le 20\,000). For the test data, you are free to assume that the sum can be paid off in the available banknotes.


The standard output should contain one integer denoting the minimal total number of bank notes sufficient to pay the sum off k.

Sample Input

2 3 5
2 2 1

Sample Output



  • 3
    4fecta  commented on Sept. 7, 2019, 10:46 a.m.

    How is this an easier version of POI - Bank Notes? I checked the constraints and they're both 2x10^4. Is the data weaker?

    • 3
      chika  commented on Sept. 7, 2019, 11:48 a.m.

      If you read the official problem statement, you'll see that you need to reconstruct the set of bank notes needed to reach the desired sum. The DMOJ problem does not require this and consequently that makes the DMOJ problem easier.

      • 3
        4fecta  commented on Sept. 7, 2019, 11:52 a.m.

        Thanks for the explanation.

  • 6
    kobortor  commented on July 21, 2018, 10:37 p.m.

    Weak testdata:

    The following testcase kills my solution


    11 4 1
    1 3 1