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

Posted 浅忆

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Round #427 B. The number on the board(Div.2)相关的知识,希望对你有一定的参考价值。

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.

 

#include <stdio.h>
#include <vector>
#include <string.h>
#include <algorithm>
//#define all(x) (x).begin(), (x).end()
using namespace std;
char a[100050];
vector <int> vec;
int main(){
    int k,n;
    scanf("%d %s",&k, a);
    n=strlen(a);
    int m=0;
    for(int i=0;i<n;i++){
        m+=a[i]-0;
        int t=a[i]-0;
        vec.push_back(9-t);
    }
    //sort(all(vec));
    sort(vec.begin(),vec.end());
    int ans=0;
    while(m<k){
        m+=vec.back();
        vec.pop_back();
        ans++;
    }
    printf("%d\n",ans);
    return 0;
}

 

以上是关于Round #427 B. The number on the board(Div.2)的主要内容,如果未能解决你的问题,请参考以下文章

Codeforces Round #585 (Div. 2) B. The Number of Products

Codeforces Round #747 (Div. 2)B. Special Numbers

Codeforces Round #747 (Div. 2)B. Special Numbers

Codeforces Round #747 (Div. 2)B. Special Numbers

Codeforces Round #342 (Div. 2) B. War of the Corporations(贪心)

Codeforces Round #384 (Div. 2) B. Chloe and the sequence(规律题)