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. Github上Laravel开源排行榜Star数31-60名

    Github上Laravel开源排行榜Star数31-60名,罗列所有 Laravel 开源扩展包,含 Github Star 数量,下载数量和项目简介.默认排序是按Star数量从多到少来排 31.c ...

  2. nessus的安装

    nessus安装 .下载地址 http://www.tenable.com/products/nessus/select-your-operating-system .获取注册码 www.nessus ...

  3. NYOJ 迷宫寻宝(一)

    # include<iostream> # include<string> # include<string.h> # include<queue> # ...

  4. springboot测试

    一.单元测试 在开发阶段的时候最重要的是单元测试了,springboot对单元测试的支持已经很完善了. 1.在pom包中添加spring-boot-starter-test包引用 <depend ...

  5. (转)Springboot日志配置(超详细,推荐)

    Spring Boot-日志配置(超详细) 更新日志: 20170810 更新通过 application.yml传递参数到 logback 中. Spring Boot-日志配置超详细 默认日志 L ...

  6. keras学习简单线性回归【1】

    转自:https://morvanzhou.github.io/tutorials/machine-learning/keras/2-1-regressor/ 总的代码的过程就是: 1.导入模块+创建 ...

  7. Editplus 竖选,竖插入技巧

    竖选方法 1,Alt + C, 然后用鼠标拖选 2,按住Alt健,再用鼠标拖选 行首行尾批量添加字符 以及其它常用正则 操作:Ctrl + H, 调出查找窗口,勾选按正则表达式查询 行首批量添加   ...

  8. UX求职:FB和微软这些大佬公司看重的UX设计师技能,你还差几条?

    最近是金三银四的求职季,当然,不管你是想求职跳槽,还是想不断充电学习升职加薪,总是要从优秀的一群人中学习. 本文依据 Facebook.微软.Booking 等互联网大佬公司的UX设计师访谈记录,整理 ...

  9. nodejs 网上下载图片到本地,并判断图片路径是否存在

    var http = require("http"); var fs = require("fs"); var server = http.createServ ...

  10. ROSETTA使用技巧随笔--score.sc处理

    对score.sc的便利操作: $ sort -n -k2 example_score_file.sc 此命令会以score文件的第二列进行排序(sort -n -k2,-n表示对数值型数据排序,可用 ...