CF219B.Special Offer! Super Price 999 Bourles!

普及/提高-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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.

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.

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.

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

波利卡普斯是一位业余商人。最近,他惊讶地发现剪刀市场完全自由!于是,波利卡普斯毫不犹豫地决定开始生产并销售这种剪刀。

波利卡普斯计算出这种剪刀的最优定价为 pp 博尔勒斯(bourles)。然而,他曾在某处读到,顾客往往会被类似“特价!超值价 999 博尔勒斯!”这样的价格所吸引。因此,波利卡普斯决定在能产生理想效果的前提下,略微调低价格。

波利卡普斯最多允许将价格下调 dd 博尔勒斯,目标是使最终价格末尾连续的数字 9 的个数尽可能多。若存在多种方案能达到相同最多的末尾 9 的个数,则选择其中价格最高的方案。

注意:波利卡普斯只统计价格末尾(即最低位起连续)的数字 9 的个数。

输入格式

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.

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.

第一行包含两个整数 pp 和 dd(1≤p≤10181 \leq p \leq 10^{18};0≤d<p0 \leq d < p)——剪刀的初始价格以及最大可能的价格降幅。

请注意,在 C++ 中读取或写入 64 位整数时,请勿使用 %lld 说明符。推荐使用 cin、cout 流,或 %I64d 说明符。

输出格式

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.

The required number shouldn't have leading zeroes.

输出所需的价格——即小于 pp 且与 pp 的差值不超过 dd 的、以最多数量的数字 9 结尾的最大价格。

该数不能有前导零。

输入输出样例

  • 输入#1

    1029 102

    输出#1

    999
  • 输入#2

    27191 17

    输出#2

    27189

输入解题思路,AI测评打分。不知道怎么写?

首页