Codeforces-The number on the board

来源:互联网 发布:java接口日志 编辑:程序博客网 时间:2024/05/17 05:52
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.


题意:给你两个数k和n,将n所有位上的数加起来,判断是否大于k,若大于或等于k,则输出0,若不大于

k,则输出最少要改变n的几位数,才能使n所有位数字加和不小于k

思路:很简单,若果改变,肯定是改变一个最小的数,让它变为9.

#include <iostream>#include<stdio.h>#include<algorithm>#include<string.h>#include<string>using namespace std;#define ll long longconst int max1=1e5+10;int cmp(int x,int y){    return x>y;}int main(){    ll k,sum,len,sumfen,i;    char s[max1],h[max1];    while(~scanf("%lld",&k))    {        sum=0;        getchar();        gets(s);        len=strlen(s);        for(i=0;i<len;i++)        {            sum+=s[i]-'0';            h[i]=9-(s[i]-'0');        }        sort(h,h+len,cmp);        sumfen=0;        if(sum>=k)        {            printf("0\n");        }        else        {            for(i=0;i<len;i++)            {                sumfen+=h[i];                if(sumfen+sum>=k)                {                    printf("%lld\n",i+1);                    break;                }            }        }    }    return 0;}