思路 CodeForces 835B

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
3
11
Output
1
Input
3
99
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 ++ ;
		}
		
	}
	
}




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值