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.

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.

Examples
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 to n.

题解:之前几次都会错题意 哇了好几次 第二天看分类说是贪心 那就贪心吧 每位数字最大到9 如果总和比k小的话 就把差最大的改为9

 #include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <map>
#include <set>
using namespace std;
#define lowbit(x) (x&(-x))
#define max(x,y) (x>y?x:y)
#define min(x,y) (x<y?x:y)
#define MAX 100000000000000000
#define MOD 1000000007
#define pi acos(-1.0)
#define ei exp(1)
#define PI 3.141592653589793238462
#define INF 0x3f3f3f3f3f
#define mem(a) (memset(a,0,sizeof(a)))
typedef long long ll;
ll gcd(ll a,ll b){
return b?gcd(b,a%b):a;
}
const int N=;
const int mod=1e9+;
char a[N];
int main()
{
int k;
scanf("%d",&k);
scanf("%s",&a);
int len=strlen(a);
int s=;
for(int i=;i<len;i++){
s+=a[i]-'';
}
sort(a,a+len);
if(s>=k) cout<<<<endl;
else {
int t=;
for(int i=;i<len;i++){
s+=-(a[i]-'');
t++;
if(s>=k){
break;
}
}
cout<<t<<endl;
}
return ;
}

Codeforce 835B - The number on the board (贪心)的更多相关文章

  1. Codeforces Round #427 (Div. 2) B. The number on the board

    引子: A题过于简单导致不敢提交,拖拖拉拉10多分钟还是决定交,太冲动交错了CE一发,我就知道又要错过一次涨分的机会.... B题还是过了,根据题意目测数组大小开1e5,居然蒙对,感觉用vector更 ...

  2. Codeforces Round #427 (Div. 2) Problem B The number on the board (Codeforces 835B) - 贪心

    Some natural number was written on the board. Its sum of digits was not less than k. But you were di ...

  3. CodeForce 359C Prime Number

    Prime Number CodeForces - 359C Simon has a prime number x and an array of non-negative integers a1,  ...

  4. cf201.div1 Number Transformation II 【贪心】

    1 题目描述: 被给一系列的正整数x1,x2,x3...xn和两个非负整数a和b,通过下面两步操作将a转化为b: 1.对当前的a减1. 2.对当前a减去a % xi (i=1,2...n). 计算a转 ...

  5. codeforce 804B Minimum number of steps

    cf劲啊 原题: We have a string of letters 'a' and 'b'. We want to perform some operations on it. On each ...

  6. (Codeforce)The number of positions

    Petr stands in line of n people, but he doesn't know exactly which position he occupies. He can say ...

  7. 【Codeforces Round #427 (Div. 2) B】The number on the board

    [Link]:http://codeforces.com/contest/835 [Description] 原本有一个数字x,它的各个数码的和原本是>=k的; 现在这个数字x,在不改变位数的情 ...

  8. Largest Beautiful Number CodeForces - 946E (贪心)

    题意:给定一个长度为偶数的数,输出小于它的最大的美丽数.如果一个数长度为偶数,且没有前导零,并存在一种排列是回文数的数为美丽数.给定的t个数长度总和不超过200000. 分析: 1.存在一种排列为回文 ...

  9. Display number of replies in disscussion board

    how to display number of replies in disscussion board I have a require about display the replies' nu ...

随机推荐

  1. Java基础知识(JAVA之泛型)

    什么是泛型?为什么要使用泛型? 泛型,即“参数化类型”.一提到参数,最熟悉的就是定义方法时有形参,然后调用此方法时传递实参.那么参数化类型怎么理解呢?顾名思义,就是将类型由原来的具体的类型参数化,类似 ...

  2. sqlserver2008出现数据库主体在该数据库中拥有架构,无法删除的解决方案

    当要删除数据库中的某个用户名的时候会报错 出现数据库主体在该数据库中拥有架构,无法删除的解决方案(MicrosoftSQLServer,错误:15138) 和sql server2000不同 第一:这 ...

  3. FCN-全卷积网络

    全卷积网络 Fully Convolutional Networks CNN 与 FCN 通常CNN网络在卷积层之后会接上若干个全连接层, 将卷积层产生的特征图(feature map)映射成一个固定 ...

  4. 【LeetCode每天一题】String to Integer (atoi)(字符串转换成数字)

    Implement atoi which converts a string to an integer.The function first discards as many whitespace ...

  5. 2019.03.30 Head first

    第一节 认识python python.exe -V python 会进入解释器 quit()命令会退出解释器 IDEL,一个python的集成开发环境,能够利用颜色突出语法的编辑器,一个调试工具,P ...

  6. 20165321 学习基础与C语言学习心得

    一.技能学习 我其实在小时候学过挺多东西,在我小学的时候,我曾经短时间地学过小提琴.拉丁舞.国画.书法,但是,由于各种原因,都没有继续学习下去.后来,在我小学四年级的时候,我接触到了二胡,于是,我开始 ...

  7. Mysql 数据库导入及导出

    Mysql 数据库导入及导出 数据库导出: 1.导出整个数据库 mysqldump -u 用户名 -p 数据库名 > 导出的文件名 mysqldump -u root -p dataname & ...

  8. Python_summary

    Q: python中出现IndentationError:unindent does not match any outer indentation levelA:复制代码的时候容易出现缩进错误,虽然 ...

  9. ****************VS编码操作实践******************

    下面是今天主要练习的内容: 运用到的内容有 {运算符.强制转换.数据类型的运用.转义字符.变量与常量.基本类型的转换等} 1) 首先我们来看  下列的编码是由三大类组成的 ① 定制变量与常量  蓝色部 ...

  10. 001-http协议-请求报文以及服务器响应状态

    Http协议的几个概念: 1.连接(Connection):浏览器和服务器之间传输数据的通道. 一般请求完毕就关闭,http不保持连接.不保持连接会降低处理速度(因为建立连接速度很慢),保持连接的话就 ...