A9808 | The Art of Dealing with ATM
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
ATMs of a well-known bank of a small country are arranged so that they can not give any amount of money requested by the user. Due to the limited size of the bill dispenser (the device that is directly giving money from an ATM) and some peculiarities of the ATM structure, you can get at most $k$ bills from it, and the bills may be of at most two distinct denominations.
For example, if a country uses bills with denominations $10$ , $50$ , $100$ , $500$ , $1000$ and $5000$ burles, then at $k=20$ such ATM can give sums $100000$ burles and $96000$ burles, but it cannot give sums $99000$ and $101000$ burles.
Let's suppose that the country uses bills of $n$ distinct denominations, and the ATM that you are using has an unlimited number of bills of each type. You know that during the day you will need to withdraw a certain amount of cash $q$ times. You know that when the ATM has multiple ways to give money, it chooses the one which requires the minimum number of bills, or displays an error message if it cannot be done. Determine the result of each of the $q$ of requests for cash withdrawal.
For example, if a country uses bills with denominations $10$ , $50$ , $100$ , $500$ , $1000$ and $5000$ burles, then at $k=20$ such ATM can give sums $100000$ burles and $96000$ burles, but it cannot give sums $99000$ and $101000$ burles.
Let's suppose that the country uses bills of $n$ distinct denominations, and the ATM that you are using has an unlimited number of bills of each type. You know that during the day you will need to withdraw a certain amount of cash $q$ times. You know that when the ATM has multiple ways to give money, it chooses the one which requires the minimum number of bills, or displays an error message if it cannot be done. Determine the result of each of the $q$ of requests for cash withdrawal.
输入格式
The first line contains two integers $n$ , $k$ ( $1<=n<=5000$ , $1<=k<=20$ ).
The next line contains $n$ space-separated integers $a_{i}$ ( $1<=a_{i}<=10^{7}$ ) — the denominations of the bills that are used in the country. Numbers $a_{i}$ follow in the strictly increasing order.
The next line contains integer $q$ ( $1<=q<=20$ ) — the number of requests for cash withdrawal that you will make.
The next $q$ lines contain numbers $x_{i}$ ( $1<=x_{i}<=2·10^{8}$ ) — the sums of money in burles that you are going to withdraw from the ATM.
The next line contains $n$ space-separated integers $a_{i}$ ( $1<=a_{i}<=10^{7}$ ) — the denominations of the bills that are used in the country. Numbers $a_{i}$ follow in the strictly increasing order.
The next line contains integer $q$ ( $1<=q<=20$ ) — the number of requests for cash withdrawal that you will make.
The next $q$ lines contain numbers $x_{i}$ ( $1<=x_{i}<=2·10^{8}$ ) — the sums of money in burles that you are going to withdraw from the ATM.
输出格式
For each request for cash withdrawal print on a single line the minimum number of bills it can be done, or print $-1$ , if it is impossible to get the corresponding sum.
输入输出样例
输入 #1
6 20 10 50 100 500 1000 5000 8 4200 100000 95000 96000 99000 10100 2015 9950
输出 #1
6 20 19 20 -1 3 -1 -1
输入 #2
5 2 1 2 3 5 8 8 1 3 5 7 9 11 13 15
输出 #2
1 1 1 2 2 2 2 -1
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted