#1531. [POI2005]Bank notes

[POI2005]Bank notes

题目描述

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 b1,b2,,bnb_1,b_2,\cdots,b_n. The BBB have concluded that the cash dispensers are to pay every sum in the smallest possible total number of notes.

TaskWrite 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.

Byteotian Bit Bank (BBB) 拥有一套先进的货币系统,这个系统一共有 nn 种面值的硬币,面值分别为 b1,b2,,bnb_1,b_2,\cdots,b_n。但是每种硬币有数量限制,现在我们想要凑出面值 kk,求最少要用多少个硬币.

输入格式

In the first line of the standard input the number of denominations is written nn, 1n2001\le n\le 200. The second line contains nn integers b1,b2,,bnb_1,b_2,\cdots,b_n, 1b1<b2<<bn20 0001\le b_1<b_2<\cdots<b_n\le 20\ 000, separated by single spaces. The third line contains nn integers c1,c2,,cnc_1,c_2,\cdots,c_n, 1ci20 0001\le c_i\le 20\ 000, also separated by single spaces; cic_i is the number of banknotes of denomination bib_i left in the cash dispenser. In the last, fourth line of input there is one integer kk - the sum to be paid off, 1k20 0001\le k\le 20\ 000 . For the test data, you are free to assume that the sum kk can be paid off in the available banknotes.

第一行一个整数 nn

第二行 nn 个整数 bib_i,表示这 nn 种硬币的面值。

第三行 nn 个整数 cic_i,表示这 nn 种硬币的数量。

第四行一个整数 kk

输出格式

The first line of the standard output should contain one integer denoting the minimal total number of bank notes sufficient to pay the sum off kk. The second line should contain nn integers, separated by single spaces, denoting the numbers of notes of subsequent denominations used to pay off the sum kk. If there are many solutions your programme should write any of them.

第一行一个整数,表示最少需要多少个硬币。

第二行 nn 个整数,表示第 ii 种硬币需要多少个。

如果有多种方案,输出其中一种即可。

输入样例

3
2 3 5
2 2 1
10

输出样例

3
1 1 1

数据范围

对于 100%100 \% 的数据,1n2001 \le n \le 2001b1<b2<<bn2×1041 \le b_1 < b_2 < \cdots < b_n \le 2 \times 10^41ci,k2×1041 \le c_i,k \le 2 \times 10^4