The number on the board

包神喜欢十分巨大的数字 。有一天,他随手写了一个很大的数字n,但是热爱做题的包神很快把它想成了一个题目,

他希望这个数字在不改变数字位数的情况下,尽可能少的改变几位,让它每一位的数字加和不小于k。这对包神

实在太简单了,他把问题留给了你!

Input

第一行包含一个整数 k (1 ≤ k ≤ 109).

第二行包含一个整数 n (1 ≤ n < 10100000).

数据保证n没有前导0,同时数据保证存在答案。

Output

Print the minimum number of digits in which the initial number and n can differ.

Example
Input
3
11
Output
1
Input
3
99
Output
0
Note

在第一个样例中,数字可以改为 12.所以更改了1位

在第二个样例中,每位之和已经大于 k. 不需要再改变,所以更改后的数字为 n.

#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int main()
{
	char a[100000];
	int b[100000];
	int i,k,p,q,l,t;
	while(scanf("%d %s",&k,a)!=EOF)
	{
		l = strlen(a);
		int sum = 0;
		for (i=0;i<l;i++)
		{
			b[i] = a[i] - '0';
			sum+=b[i];
		} 
		sort(b,b+l);
		if (sum>=k)
			printf("0\n");
		else
		{
			p = q = t = 0;
			
			p = k - sum;
			while (q<p)
			{
				q += 9-b[t];
				t++;
			}
			printf("%d\n",t);
		}
	}
	return 0;
}
反思:oj提交超时不一定是数组范围开大了,开小了也会造成超时。

猜你喜欢

转载自blog.csdn.net/qq_40912854/article/details/80568486
今日推荐