A12774 | Optimal Currency Exchange
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Andrew was very excited to participate in Olympiad of Metropolises. Days flew by quickly, and Andrew is already at the airport, ready to go home. He has $n$ rubles left, and would like to exchange them to euro and dollar bills. Andrew can mix dollar bills and euro bills in whatever way he wants. The price of one dollar is $d$ rubles, and one euro costs $e$ rubles.
Recall that there exist the following dollar bills: $1$ , $2$ , $5$ , $10$ , $20$ , $50$ , $100$ , and the following euro bills — $5$ , $10$ , $20$ , $50$ , $100$ , $200$ (note that, in this problem we do not consider the $500$ euro bill, it is hard to find such bills in the currency exchange points). Andrew can buy any combination of bills, and his goal is to minimize the total number of rubles he will have after the exchange.
Help him — write a program that given integers $n$ , $e$ and $d$ , finds the minimum number of rubles Andrew can get after buying dollar and euro bills.
Recall that there exist the following dollar bills: $1$ , $2$ , $5$ , $10$ , $20$ , $50$ , $100$ , and the following euro bills — $5$ , $10$ , $20$ , $50$ , $100$ , $200$ (note that, in this problem we do not consider the $500$ euro bill, it is hard to find such bills in the currency exchange points). Andrew can buy any combination of bills, and his goal is to minimize the total number of rubles he will have after the exchange.
Help him — write a program that given integers $n$ , $e$ and $d$ , finds the minimum number of rubles Andrew can get after buying dollar and euro bills.
输入格式
The first line of the input contains one integer $n$ ( $1 \leq n \leq 10^8$ ) — the initial sum in rubles Andrew has.
The second line of the input contains one integer $d$ ( $30 \leq d \leq 100$ ) — the price of one dollar in rubles.
The third line of the input contains integer $e$ ( $30 \leq e \leq 100$ ) — the price of one euro in rubles.
The second line of the input contains one integer $d$ ( $30 \leq d \leq 100$ ) — the price of one dollar in rubles.
The third line of the input contains integer $e$ ( $30 \leq e \leq 100$ ) — the price of one euro in rubles.
输出格式
Output one integer — the minimum number of rubles Andrew can have after buying dollar and euro bills optimally.
输入输出样例
输入 #1
100 60 70
输出 #1
40
输入 #2
410 55 70
输出 #2
5
输入 #3
600 60 70
输出 #3
0
In the first example, we can buy just $1$ dollar because there is no $1$ euro bill.
In the second example, optimal exchange is to buy $5$ euro and $1$ dollar.
In the third example, optimal exchange is to buy $10$ dollars in one bill.
In the second example, optimal exchange is to buy $5$ euro and $1$ dollar.
In the third example, optimal exchange is to buy $10$ dollars in one bill.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted