CF 135 DIV2 B Special Offer! Super Price 999 Bourles! 思维

time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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.

Input

The first line contains two integers p and d (1 ≤ p ≤ 10180 ≤ 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.

Output

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.

Sample test(s)
input
1029 102
output
999
input
27191 17
output
27189
题面 前面是价格 后面是最大的降价幅度 让你找到一个在降价区间内找一个最大的数  这个数的末尾9的个数也必须最多。

再举两个栗子 比如199 100 是 199   198 100 是99

我的思路就是让第一个数不断% 每次让取掉最高位直到小于后面的降价幅度。

需要注意的是 199 100 99这种情况 需要单独讨论。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long int ll;
int main()
{
    //freopen("in.txt","r",stdin);
    ll a,b;
    cin>>a>>b;
    if(b==0)
        cout<<a<<endl;
    else
    {
    ll aa=a;
    ll k=1000000000;
    k=k*k;
    while(b<=aa)
    {
        aa=aa%k;
        k=k/10;
    }
    ll t=aa;
    int ans1=0,ans2=0;//分别记录可能输出的末尾的9的个数 和原价格的末尾的9的个数 这个就是再考虑 199 100 是199 而非99
   while(t%10==9)
    {
        t=t/10;
        ans1++;
    }
    t=a-aa-1;
    while(t%10==9)
    {
        t=t/10;
        ans2++;
    }
    if(ans2>ans1) cout<<a-aa-1<<endl;
    else cout<<a<<endl;
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值