codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

898B.md (2249B)


      1 Source: https://codeforces.com/problemset/problem/898/B
      2 
      3 B. Proper Nutrition
      4 
      5 time limit per test
      6 
      7 1 second
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 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.
     22 
     23 Find out if it's possible to buy some amount of bottles of Ber-Cola and Bars bars and spend exactly *n* burles.
     24 
     25 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.
     26 
     27 Input
     28 
     29 First line contains single integer *n* (1 ≤ *n* ≤ 10 000 000) — amount of money, that Vasya has.
     30 
     31 Second line contains single integer *a* (1 ≤ *a* ≤ 10 000 000) — cost of one bottle of Ber-Cola.
     32 
     33 Third line contains single integer *b* (1 ≤ *b* ≤ 10 000 000) — cost of one Bars bar.
     34 
     35 Output
     36 
     37 If Vasya can't buy Bars and Ber-Cola in such a way to spend exactly *n* burles print «NO» (without quotes).
     38 
     39 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.
     40 
     41 Any of numbers *x* and *y* can be equal 0.
     42 
     43 Examples
     44 
     45 Input
     46 
     47 ```
     48 7  
     49 2  
     50 3
     51 ```
     52 
     53 Output
     54 
     55 ```
     56 YES  
     57 2 1
     58 ```
     59 
     60 Input
     61 
     62 ```
     63 100  
     64 25  
     65 10
     66 ```
     67 
     68 Output
     69 
     70 ```
     71 YES  
     72 0 10
     73 ```
     74 
     75 Input
     76 
     77 ```
     78 15  
     79 4  
     80 8
     81 ```
     82 
     83 Output
     84 
     85 ```
     86 NO
     87 ```
     88 
     89 Input
     90 
     91 ```
     92 9960594  
     93 2551  
     94 2557
     95 ```
     96 
     97 Output
     98 
     99 ```
    100 YES  
    101 1951 1949
    102 ```
    103 
    104 Note
    105 
    106 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.
    107 
    108 In second example Vasya can spend exactly *n* burles multiple ways:
    109 
    110 * buy two bottles of Ber-Cola and five Bars bars;
    111 * buy four bottles of Ber-Cola and don't buy Bars bars;
    112 * don't buy Ber-Cola and buy 10 Bars bars.
    113 
    114 In third example it's impossible to but Ber-Cola and Bars bars in order to spend exactly *n* burles.