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. mysql 错误2002

    ERROR 2002 (HY000): Can’t connect to local MySQL server throughsocket ‘/tmp/mysql.sock’ (2) 今天遇到的200 ...

  2. POJ 3461 Oulipo(模式串在主串中出现次数 可重叠)

    Oulipo [题目链接]Oulipo [题目类型]KMP &题意: 给你两个字符串p和s,求出p在s中出现的次数. &题解: kmpC函数就是解题的,其中也就j=nex[j]难理解一 ...

  3. JAVA8流操作

    * Stream 的三个操作步骤: * 1创建Stream * 2中间操作 * 3终止操作 package airycode_java8.nice6; import airycode_java8.ni ...

  4. [Unit Test] Unit Test Brief Introduction

    Levels of Testing- Acceptance- Performance- Functional- Integration- Unit Why Unit Testing- Feedback ...

  5. 20155228 基于VirtualBox安装Ubuntu和学习linux命令的学习经历和心得

    一.虚拟机VirtualBox的下载安装 基于VirtualBox虚拟机安装Ubuntu图文教程 虽然娄老师的教程对于VirtualBox的下载安装讲的很简单,可以说是一笔带过,但是我在下载安装的过程 ...

  6. python seek()方法报错:“io.UnsupportedOperation: can't do nonzero cur-relative seeks”

    今天使用seek()时报错了, 看下图 然后就百度了一下,找到了解决方法 这篇博客https://www.cnblogs.com/xisheng/p/7636736.html 帮忙解决了问题, 照理说 ...

  7. Beta分布深入理解

    一些公式 Gamma函数 (1) 贝叶斯公式 (2) 贝叶斯公式计算二项分布概率 现在有一枚未知硬币,我们想要计算抛出后出现正面的概率.我们使用贝叶斯公式计算硬币出现正面的概率.硬币出现正反率的概率和 ...

  8. 三角形垂点坐标js算法(三点定圆求圆心)

    已知平面三点坐标A(x1, y1).B(x2, y2).C(x3, y3),三点定圆也就是三角形的中垂线交点, //平面三点定位算法 function locate(x1, y1, x2, y2, x ...

  9. HTTP接口-跨域-callback

    1.客户端和正常调用非跨域接口一样2.服务端返回的时候用callback+(返回值)的方式返回结果. callback为客户端的隐藏参数.public String converJsonResultS ...

  10. linux下postgresql的连接数配置

    1.查询当前连接数: select count(*) from pg_stat_activity; 2.查询最大连接数 show max_connections; 3.修改最大连接数 SHOW con ...