Codeforces 219B Special offer! Super Price 999 bourles!

Source: Internet
Author: User

Special offer! Super Price 999 bourles!Time limit:1000MS Memory Limit:262144KB 64bit IO Format:%i64d &%i6 4u SubmitStatusPracticecodeforces 219B

Description

Polycarpus is an amateur businessman. Recently he was surprised to find out and that the market for paper scissors is completely free! Without further ado, Polycarpus decided to start producing and selling such scissors.

Polycaprus calculated that the optimal celling price for such scissors would is p bourles. However, he read somewhere that customers is attracted by prices the 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.

Polycarpus agrees to lower, the price is no more than D Bourles so that's the number of nines at the end of the Resulting price is maximum. If there is several ways to does it, he chooses the maximum possible price.

Note, Polycarpus counts only the trailing nines in a price.

Input

The first line contains the integers p and D (1≤ p ≤1018; 0≤ D < p)-the initial price of scissors and the maximum possible price reduction.

%lld specifier to read or write 64-bit integers inс++. It is preferred to use CIN, cout streams or the%i64d specifier.

Output

Print the required price-the maximum price it ends with the largest number of nines and that's less than p< /c11> by no more than D.

The required number shouldn ' t has leading zeroes.

Sample Input

Input
1029 102
Output
999
Input
27191 17
Output
27189
1#include <stdio.h>2#include <string.h>3#include <algorithm>4 using namespacestd;5 6 intnnLong Longa)7 {8     intSi=0;9      while(a)Ten     { Onea=a/Ten; Asi++; -     } -     returnsi; the } -  - Long LongPoLong LongSinty) - { +      for(intI=1; i<=y;i++) -     { +s=s*Ten; A     } at     returns; - } -  - intMain () - { -     Long Longp,d,q; in     intn,i,j,k; -      while(SCANF ("%i64d%i64d", &p,&d)! =EOF) to     { +n=nn (p); -         if(n==1) theprintf"%i64d\n", p); *         Else $          for(i=1; i<=n;i++)Panax Notoginseng         { -Q=po (P/po (1, n-i), N-i); the              for(j=n-i;j>=1; j--) +             { AQ=q+po (9, J-1); the             } +             if(q==p) -             { $printf"%i64d\n", Q); $                  Break; -             } -Q=po (P/po (1, N-i)-1, N-i); the              for(j=n-i;j>=1; j--) -             {WuyiQ=q+po (9, J-1); the             } -             if(p-q<=d) Wu             { -printf"%i64d\n", Q); About                  Break; $             } -         } -     } -     return 0; A}
View Code

Codeforces 219B Special offer! Super Price 999 bourles!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.