经典简约
清爽简洁,回归本真
液态水晶
毛玻璃+霓虹光带
赛博朋克
霓虹故障艺术风
🚫
违规操作检测
禁止使用右键菜单
⚠️ 此操作已被系统记录
1

Exact Change

📝 题解 🔵 仅限 C++
题目描述
<ul> <li>Seller: That will be fourteen dollars.</li> <li>Buyer: Here's a twenty.</li> <li>Seller: Sorry, I don't have any change.</li> <li>Buyer: OK, here's a ten and a five. Keep the change.</li> </ul> <p>When travelling to remote locations, it is often helpful to bring cash, in case you want to buy something from someone who does not accept credit or debit cards. It is also helpful to bring a variety of denominations in case the seller does not have change. Even so, you may not have the exact amount, and will have to pay a little bit more than full price. The same problem can arise even in urban locations, for example with vending machines that do not return change.</p> <p>Of course, you would like to minimize the amount you pay (though you must pay at least as much as the value of the item). Moreover, while paying the minimum amount, you would like to minimize the number of coins or bills that you pay out.</p>
输入格式
<p>The first line of input contains one integer specifying the number of test cases to follow. Each test case begins with a line containing an integer, the price in cents of the item you would like to buy. The price will not exceed 10 000 cents (i.e., $100). The following line contains a single integer <i>n</i>, the number of bills and coins that you have. The number <i>n</i> is at most 100. The following <i>n</i> lines each contain one integer, the value in cents of each bill or coin that you have. Note that the denominations can be any number of cents; they are not limited to the values of coins and bills that we usually use in Canada. However, no bill or coin will have a value greater than 10 000 cents ($100). The total value of your bills and coins will always be equal to or greater than the price of the item.</p>
输出格式
<p>For each test case, output a single line containing two integers: the total amount paid (in cents), and the total number of coins and bills used.</p>
样例
样例输入 1
1 1400 3 500 1000 2000
样例输出 1
1500 2
提交代码
请先登录后提交

🤖 AI 解题助手

DeepSeek
就绪
👋 你好!我是 AI 解题助手。
我已阅读了这道题,可以帮你分析思路、提供代码示例。
⚠️ 请先登录后使用