Codeforce 835B - The number on the board (贪心)

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 ;
}
上一篇:hue,kylin,ambari


下一篇:单片机学习(三)开发板动态数码管的控制