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提交超时不一定是数组范围开大了,开小了也会造成超时。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Given the grid below for the game of ACSL Patolli, utilize the following rules to play the game. All rules must be applied in the sequential order listed. 1 . There are 2 players. Each player has 3 markers. 2. The markers move according to the roll of a die (1 – 6). 3. Markers move in numerical order around the grid. 4. If, on a die roll, a marker lands on an occupied location, then that marker loses its turn and remains at its previous location. 5. A marker can jump over another marker on its way to finish its move. 6. A marker finishes its way around the grid when it lands on location 52. It is then removed from the board. A move can’t take a marker beyond location 52. If it does, the marker remains at its previous location. 7. If, on a die roll, a marker lands on an unoccupied location that is a prime number, the marker then moves six locations forward. However, it stops immediately before any occupied location. 8. If, on a die roll, a marker lands on an unoccupied location that is a perfect square greater than 4, the marker then moves 6 locations backwards. However, it stops immediately before any occupied location. 9. If, on a die roll, a marker lands on an unoccupied location that is neither a prime number nor a perfect square, then determine if the marker made at least one horizontal move followed by at least one vertical move (such as going from 6 to 8, 11 to 13, 26 to 28 … but not 2 to 4 or 30 to 32). In that case, the marker can only land on a location on its path that is a multiple of the die roll value even if it moves a smaller distance than the die roll value. However, if all the locations in its path that are multiples are occupied, then the marker does not move from its current location. The rules listed in #7 and #8 do not apply when using #9.
最新发布
03-02

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值