TopCoder

User's AC Ratio

NaN% (0/0)

Submission's AC Ratio

NaN% (0/0)

Tags

Description

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,b_2,...,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, and finds some way of paying it off as well (using the determined minimal number of notes, of course)

  • writes the result to the standard output.

Input Format

There are multiple test cases in the input file, terminated by EOF. For each test case:

In the first line of the standard input the number of denominations is written n ,1<=n<=200. The second line contains n integers b_1,b_2,...,b_n, 1<=b_1< b_2< ...< b_n<=20000 , separated by single spaces. The third line contains n integers c_1,c_2,...,c_n , all of them is not less than 1 and not greater than 20000, also separated by single spaces; 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<=k<=20000 . For the test data, you are free to assume that the sum k can be paid off in the available banknotes.

Output Format

For each test case please output an integer denoting the minimal total number of bank notes sufficient to pay the sum off k.

Sample Input 1

3
2 3 5
2 2 1
10

Sample Output 1

3

Hints

Problem Source

Migrated from old NTUJ.

POI12th stage II

Subtasks

No. Testdata Range Score

Testdata and Limits

No. Time Limit (ms) Memory Limit (VSS, KiB) Output Limit (KiB) Subtasks
0 2000 65536 200