codeforces-scrape

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

219B.md (1640B)


      1 Source: https://codeforces.com/problemset/problem/219/B
      2 
      3 B. Special Offer! Super Price 999 Bourles!
      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 stdin
     16 
     17 output
     18 
     19 stdout
     20 
     21 Polycarpus is an amateur businessman. Recently he was surprised to find out that the market for paper scissors is completely free! Without further ado, Polycarpus decided to start producing and selling such scissors.
     22 
     23 Polycaprus calculated that the optimal celling price for such scissors would be *p* bourles. However, he read somewhere that customers are attracted by prices that say something like "Special Offer! Super price 999 bourles!". So Polycarpus decided to lower the price a little if it leads to the desired effect.
     24 
     25 Polycarpus agrees to lower the price by no more than *d* bourles so that the number of nines at the end of the resulting price is maximum. If there are several ways to do it, he chooses the maximum possible price.
     26 
     27 Note, Polycarpus counts only the trailing nines in a price.
     28 
     29 Input
     30 
     31 The first line contains two integers *p* and *d* (1 ≤ *p* ≤ 1018; 0 ≤ *d* < *p*) — the initial price of scissors and the maximum possible price reduction.
     32 
     33 Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier.
     34 
     35 Output
     36 
     37 Print the required price — the maximum price that ends with the largest number of nines and that is less than *p* by no more than *d*.
     38 
     39 The required number shouldn't have leading zeroes.
     40 
     41 Examples
     42 
     43 Input
     44 
     45 ```
     46 1029 102
     47 ```
     48 
     49 Output
     50 
     51 ```
     52 999
     53 ```
     54 
     55 Input
     56 
     57 ```
     58 27191 17
     59 ```
     60 
     61 Output
     62 
     63 ```
     64 27189
     65 ```