The number on the board 【CodeForces - 835B】

  如果读懂题目,那就是一道水题,然而我今天就栽在了这上面,上午的时候打训练赛的时候心态简直炸了(或许所有的ACMer的通病吧),全程只过了一道题,另外在一道并查集和一道二分low_bound的题左右徘徊了两个回合,WA了,就没做下去,或许吧,调整心态,下周面对最后一场尽力而为!

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了17发还一直在以为是不是高精度取余写错的也没资格说这道题是道水题吧,题意翻译挺难,就是让你改变其中几位的位数使得所有数位的数字之和>=K(可以直接改变到9),问:最小需要改变几个数位

 

完整代码:

//The number on the board ——CodeForces - 835B
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <limits>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#define lowbit(x) ( x&(-x) )
using namespace std;
typedef long long ll;
ll K;
ll sum=0;
char s;
int mp[100005];
bool cmp(int e1, int e2)
{
    return e1>e2;
}
int main()
{
    while(scanf("%lld",&K)!=EOF)
    {
        sum=0;
        getchar();
        int cnt=0;
        while(scanf("%c",&s)!=EOF)
        {
            if(s=='\n') break;
            mp[++cnt]=s-'0';
            sum+=mp[cnt];
            mp[cnt]=9-mp[cnt];
        }
        if(sum>=K)
        {
            printf("0\n");
            continue;
        }
        int for_exp=sum;
        sort(mp+1, mp+1+cnt, cmp);
        for(int i=1; i<=cnt; i++)
        {
            for_exp+=mp[i];
            if(for_exp>=K)
            {
                printf("%d\n",i);
                break;
            }
        }
    }
    return 0;
}

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Wuliwuliii

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值