思路 CodeForces 835B

来源:互联网 发布:用友软件的优势 编辑:程序博客网 时间:2024/06/07 17:33

Some natural number was written on the board. Its sum of digits was not less thank. But you were distracted a bit, and someone changed this number ton, 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.

Example
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 ton.


题意:要使第二个数的每一位相加之和大于第一个数,至少需要改变第二个数中的几位数字。1->2\3\4\5\6\7\8\9
#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;char k[100005];int b[100005];int main(){int n;scanf("%d %s",&n,k);int len = strlen(k);int sum = 0;for(int i = 0; i < len; i++){b[i] = k[i]-'0';sum = sum + b[i];}sort(b,b+len);int count = 0;if(sum >= n) { printf("0\n");return 0;}//先判断一次for(int i = 0; i < len; i++){sum = sum + 9 - b[i];count ++ ;if(sum >= n) { printf("%d\n",count); return 0;} }}
#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;char k[100005];int b[100005];int main(){int n;while(~scanf("%d%s",&n,k)){int len = strlen(k);int sum = 0;for(int i = 0; i < len; i++){b[i] = k[i]-'0';sum = sum + b[i];}sort(b,b+len);int count = 0;for(int i = 0; i <= len; i++)//注意要多判断一次因为是先判断再加{if(sum >= n) { printf("%d\n",count);break;} sum = sum + 9 - b[i];count ++ ;}}}

原创粉丝点击