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;
}

猜你喜欢

转载自blog.csdn.net/qq_41730082/article/details/81368572