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,然后给出改动一些位的数字后的数字,求最少改动多少位
思路:如果改动后的n位之和大于等于k那么答案就是0;否则统计0~9出现的次数贪心的选择小的数字变成9.
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <vector>
#include <bitset>
using namespace std;
#define LL long long
const int INF = 0x3f3f3f3f;
#define mod 10000007
#define mem(a,b) memset(a,b,sizeof a)
int main()
{
int n;
char s[100005];
int a[10];
while(~scanf("%d",&n))
{
cin>>s;
int k=strlen(s);
int sum=0;
mem(a,0);
for(int i=0;i<k;i++)
{
sum+=s[i]-'0';
a[s[i]-'0']++;
}
if(sum>=n)
{
printf("0\n");
continue;
}
else
{
int x=n-sum;
int ans=0;
for(int i=0;i<=9;i++)
{
if(a[i]*(9-i)<x)
{
x-=a[i]*(9-i);
ans+=a[i];
}
else
{
ans+=(x + 9 - i - 1)/(9-i);
break;
}
}
printf("%d\n",ans);
}
}
return 0;
}