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.
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.
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 to n.
这道题题意就是先给你一个数k,然后给你一串自然数。求最少多少位自然数经过变化可以使整串自然数相加的和大于等于k。
AC代码:
#include<iostream>
#include<algorithm>
#include<cstring>
#include<string>
#include<cstdio>
using namespace std;
char k[1111111];
int cnt[11];
int main()
{
long long int n;
while(cin>>n)
{
scanf("%s",k);
memset(cnt,0,sizeof(cnt));
for(int i=0;k[i];i++)
{
n-=(k[i]-'0');
cnt[k[i]-'0']++;
if(n<=0)
break;
}
if(n<=0)
{
cout<<0<<endl;
continue;
}
int res=0;
for(int i=0;i<=9;i++)
{
while(cnt[i])
{
n-=(9-i);
res++;
cnt[i]--;
if(n<=0)
break;
}
if(n<=0)
break;
}
cout<<res<<endl;
}
return 0;
}