codeforces 835B The number on the board

来源:互联网 发布:内功最高境界身知 编辑:程序博客网 时间:2024/06/06 23:18

点击打开链接

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
311
output
1
input
399
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.

有趣的贪心。
#include<cstdio>#include<cstring>#include<algorithm>using namespace std;int main(){    int k,a[100005];    char s[100005];    scanf("%d",&k);    scanf("%s",s);    int sum=0,len=strlen(s);    for(int i=0; i<len; i++)    {        a[i]=s[i]-'0';        sum+=a[i];    }    if(sum>=k)        printf("0\n");    else    {        int w=0;        sort(a,a+len);        for(int i=0;i<len;i++)        {            sum+=9-a[i];            w++;            if(sum>=k)                break;        }        printf("%d\n",w);    }    return 0;}


原创粉丝点击