codeforces-scrape

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

770B.md (920B)


      1 Source: https://codeforces.com/problemset/problem/770/B
      2 
      3 B. Maximize Sum of Digits
      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 Anton has the integer *x*. He is interested what positive integer, which doesn't exceed *x*, has the maximum sum of digits.
     22 
     23 Your task is to help Anton and to find the integer that interests him. If there are several such integers, determine the biggest of them.
     24 
     25 Input
     26 
     27 The first line contains the positive integer *x* (1 ≤ *x* ≤ 1018) — the integer which Anton has.
     28 
     29 Output
     30 
     31 Print the positive integer which doesn't exceed *x* and has the maximum sum of digits. If there are several such integers, print the biggest of them. Printed integer must not contain leading zeros.
     32 
     33 Examples
     34 
     35 Input
     36 
     37 ```
     38 100
     39 ```
     40 
     41 Output
     42 
     43 ```
     44 99
     45 ```
     46 
     47 Input
     48 
     49 ```
     50 48
     51 ```
     52 
     53 Output
     54 
     55 ```
     56 48
     57 ```
     58 
     59 Input
     60 
     61 ```
     62 521
     63 ```
     64 
     65 Output
     66 
     67 ```
     68 499
     69 ```