A11388 | Proper Nutrition
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Vasya has $n$ burles. One bottle of Ber-Cola costs $a$ burles and one Bars bar costs $b$ burles. He can buy any non-negative integer number of bottles of Ber-Cola and any non-negative integer number of Bars bars.
Find out if it's possible to buy some amount of bottles of Ber-Cola and Bars bars and spend exactly $n$ burles.
In other words, you should find two non-negative integers $x$ and $y$ such that Vasya can buy $x$ bottles of Ber-Cola and $y$ Bars bars and $x·a+y·b=n$ or tell that it's impossible.
Find out if it's possible to buy some amount of bottles of Ber-Cola and Bars bars and spend exactly $n$ burles.
In other words, you should find two non-negative integers $x$ and $y$ such that Vasya can buy $x$ bottles of Ber-Cola and $y$ Bars bars and $x·a+y·b=n$ or tell that it's impossible.
输入格式
First line contains single integer $n$ ( $1<=n<=10000000$ ) — amount of money, that Vasya has.
Second line contains single integer $a$ ( $1<=a<=10000000$ ) — cost of one bottle of Ber-Cola.
Third line contains single integer $b$ ( $1<=b<=10000000$ ) — cost of one Bars bar.
Second line contains single integer $a$ ( $1<=a<=10000000$ ) — cost of one bottle of Ber-Cola.
Third line contains single integer $b$ ( $1<=b<=10000000$ ) — cost of one Bars bar.
输出格式
If Vasya can't buy Bars and Ber-Cola in such a way to spend exactly $n$ burles print «NO» (without quotes).
Otherwise in first line print «YES» (without quotes). In second line print two non-negative integers $x$ and $y$ — number of bottles of Ber-Cola and number of Bars bars Vasya should buy in order to spend exactly $n$ burles, i.e. $x·a+y·b=n$ . If there are multiple answers print any of them.
Any of numbers $x$ and $y$ can be equal $0$ .
Otherwise in first line print «YES» (without quotes). In second line print two non-negative integers $x$ and $y$ — number of bottles of Ber-Cola and number of Bars bars Vasya should buy in order to spend exactly $n$ burles, i.e. $x·a+y·b=n$ . If there are multiple answers print any of them.
Any of numbers $x$ and $y$ can be equal $0$ .
输入输出样例
输入 #1
7 2 3
输出 #1
YES 2 1
输入 #2
100 25 10
输出 #2
YES 0 10
输入 #3
15 4 8
输出 #3
NO
输入 #4
9960594 2551 2557
输出 #4
YES 1951 1949
In first example Vasya can buy two bottles of Ber-Cola and one Bars bar. He will spend exactly $2·2+1·3=7$ burles.
In second example Vasya can spend exactly $n$ burles multiple ways:
- buy two bottles of Ber-Cola and five Bars bars;
- buy four bottles of Ber-Cola and don't buy Bars bars;
- don't buy Ber-Cola and buy $10$ Bars bars.
In third example it's impossible to but Ber-Cola and Bars bars in order to spend exactly $n$ burles.
In second example Vasya can spend exactly $n$ burles multiple ways:
- buy two bottles of Ber-Cola and five Bars bars;
- buy four bottles of Ber-Cola and don't buy Bars bars;
- don't buy Ber-Cola and buy $10$ Bars bars.
In third example it's impossible to but Ber-Cola and Bars bars in order to spend exactly $n$ burles.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted