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.


  题目大意 问给定一个数,如果要使各位数字之和能够超过k,问至少要改动多少个数字。

  从数字小的开始贪心。贪心地将它改成9.

Code

 /**
* Codefores
* Problem#835B
* Accepted
* Time:16ms
* Memory:2100k
*/
#include <bits/stdc++.h>
#ifndef WIN32
#define Auto "%lld"
#else
#define Auto "%I64d"
#endif
using namespace std;
typedef bool boolean;
const signed int inf = (signed)((1u << ) - );
const signed long long llf = (signed long long)((1ull << ) - );
const double eps = 1e-;
const int binary_limit = ;
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a, min(b, c))
template<typename T>
inline boolean readInteger(T& u){
char x;
int aFlag = ;
while(!isdigit((x = getchar())) && x != '-' && x != -);
if(x == -) {
ungetc(x, stdin);
return false;
}
if(x == '-'){
x = getchar();
aFlag = -;
}
for(u = x - ''; isdigit((x = getchar())); u = (u << ) + (u << ) + x - '');
ungetc(x, stdin);
u *= aFlag;
return true;
} int k;
int sum = , len, res = ;
char str[];
int counter[]; inline void init() {
scanf("%d%s", &k, &str);
len = strlen(str);
memset(counter, , sizeof(counter));
for(int i = ; i < len; i++)
counter[str[i] - '']++, sum += str[i] - '';
} inline void solve() {
int fin = ;
while(sum < k && fin < ) {
while(counter[fin] == ) fin++;
sum += - fin, res++;
counter[fin]--;
}
if(fin == && sum < k) res += ceil(k - sum * 1.0 / );
printf("%d\n", res);
} int main() {
init();
solve();
return ;
}

Codeforces Round #427 (Div. 2) Problem B The number on the board (Codeforces 835B) - 贪心的更多相关文章

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

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

  2. Codeforces Round #427 (Div. 2) Problem D Palindromic characteristics (Codeforces 835D) - 记忆化搜索

    Palindromic characteristics of string s with length |s| is a sequence of |s| integers, where k-th nu ...

  3. Codeforces Round #427 (Div. 2) Problem C Star sky (Codeforces 835C) - 前缀和

    The Cartesian coordinate system is set in the sky. There you can see n stars, the i-th has coordinat ...

  4. Codeforces Round #427 (Div. 2) Problem A Key races (Codeforces 835 A)

    Two boys decided to compete in text typing on the site "Key races". During the competition ...

  5. CodeForces 835C - Star sky | Codeforces Round #427 (Div. 2)

    s <= c是最骚的,数组在那一维开了10,第八组样例直接爆了- - /* CodeForces 835C - Star sky [ 前缀和,容斥 ] | Codeforces Round #4 ...

  6. CodeForces 835D - Palindromic characteristics | Codeforces Round #427 (Div. 2)

    证明在Tutorial的评论版里 /* CodeForces 835D - Palindromic characteristics [ 分析,DP ] | Codeforces Round #427 ...

  7. DP+埃氏筛法 Codeforces Round #304 (Div. 2) D. Soldier and Number Game

    题目传送门 /* 题意:b+1,b+2,...,a 所有数的素数个数和 DP+埃氏筛法:dp[i] 记录i的素数个数和,若i是素数,则为1:否则它可以从一个数乘以素数递推过来 最后改为i之前所有素数个 ...

  8. 数学+DP Codeforces Round #304 (Div. 2) D. Soldier and Number Game

    题目传送门 /* 题意:这题就是求b+1到a的因子个数和. 数学+DP:a[i]保存i的最小因子,dp[i] = dp[i/a[i]] +1;再来一个前缀和 */ /***************** ...

  9. Codeforces Round #716 (Div. 2), problem: (B) AND 0, Sum Big位运算思维

    & -- 位运算之一,有0则0 原题链接 Problem - 1514B - Codeforces 题目 Example input 2 2 2 100000 20 output 4 2267 ...

随机推荐

  1. 18.搭建 vue 环境

    第一步 node环境安装 1.1 如果本机没有安装node运行环境,请下载node 安装包进行安装1.2 如果本机已经安装node的运行换,请更新至最新的node 版本下载地址:https://nod ...

  2. 集体干死java 在启动.sh

    #!/bin/bash#reboot .jar#author wangdonghuipid=`ps -ef |grep java |awk '{print $2}'`echo $pidecho'--- ...

  3. oracle将unix 时间戳转换为date类型

    select to_date('19700101','yyyyMMdd')+numtodsinterval(8*3600,'second')+numtodsinterval(60,'second') ...

  4. gispro设置标注属性字体样式设置

    为了应对电子地图和卫星影像的底图,标注样式选择比较关键.挑选了黑字白色晕圈效果.记住不是设置字体轮廓. 因为字体宽度(字粗)有限,设置轮廓直接把字体本身的颜色覆盖了

  5. Unity shader学习之渐变纹理

    渐变纹理,及使用纹理来存储漫反射光照的结果,这种技术在游戏<军团要塞2>中流行起来,它也是由Valve公司(提出半兰伯特光照技术的公司)提出来的,他们使用这种技术来渲染游戏中具有插画风格的 ...

  6. linux工作目录切换命令

    1.pwd命令 pwd命令用于显示用户当前所处的工作目录,格式为“pwd [选项]”. 2.cd命令 cd命令用于切换工作路径,格式为“cd [目录名称]”. 这个命令应该是最常用的一个Linux命令 ...

  7. DataSet 读取xml 报错有非法字符

    private void Bind() { string strLogPath = ConfigurationSettings.AppSettings["LOG_PATH"].To ...

  8. 转 VS2010 RDLC 横向合并时“未正确设置 tablix“Tablix1”的 FixedData 属性”错误解决方法 .

    最近在使用Rdlc做报表打印,有些报表的表头需要合并表头.Rdlc本身提供了横向合并的工具,但是在实际合并的时候,会出现“未正确设置 tablix“Tablix1”的 FixedData 属性.除非在 ...

  9. c扩展开发

    为什么要用C扩展 C是静态编译的,执行效率比PHP代码高很多.同样的运算代码,使用C来开发,性能会比PHP要提升数百倍.IO操作如CURL,因为耗时主要在IOWait上,C扩展没有明显优势. 另外C扩 ...

  10. html5-文件的基本格式

    <!DOCTYPE html><html lang="en"><head>    <meta charset="UTF-8&qu ...