Codeforces 835B

B. The number on the board
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Some natural number was written on the board. Its sum of digits was not less than k. But you were distracted a bit, and someone changed this number to n, replacing some digits with others. It's known that the length of the number didn't change.

You have to find the minimum number of digits in which these two numbers can differ.

Input

The first line contains integer k (1 ≤ k ≤ 109).

The second line contains integer n (1 ≤ n < 10100000).

There are no leading zeros in n. It's guaranteed that this situation is possible.

Output

Print the minimum number of digits in which the initial number and n can differ.

Examples
input
3
11
output
1
input
3
99
output
0
Note

In the first example, the initial number could be 12.

In the second example the sum of the digits of n is not less than k. The initial number could be equal to n.

思路:这题在比赛时一直wa,完全找不出错误,第二天听人一讲题意,原来这题要求的是要变得最少的个数,而不是最小的位数。

代码:

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <cmath>
#include <queue>
#include <map>
#include <algorithm>
#include <stdlib.h>
using namespace std;
#define ma(a) memset(a,0,sizeof(a))
#define ll long long
int main()
{
    ll k;
    while(cin>>k)
    {
        char n[111111];
        cin>>n;
        int len=strlen(n);
        sort(n,n+len);
        ll sum=0;
        int i;
        for(i=0;i<len;i++)
        {
            sum+=n[i]-'0';
        }
        if(sum>=k)
        {
            cout<<0<<endl;
            continue;
        }
        ll z=0;
        for(i=0;i<len;i++)
        {     if(sum<k)z++;
            else break;
            sum=sum+9-(n[i]-'0');

        }
        cout<<z<<endl;
    }
    return 0;
}


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值