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.
InputThe 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.
Print the minimum number of digits in which the initial number and n can differ.
3 11
1
3 99
0
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.
#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 ++ ; } } }