The number on the board

B. The number on the board
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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.

这题比赛的时候一直wa,原来是读错题意了(尴尬)。

其实读懂题意也是水题一道。

用了一个vector

 1 #include <bits/stdc++.h>
 2 #define ll long long int
 3 #define M 100005
 4 using namespace std;
 5 char s[M];
 6 vector<int> v;
 7 int main(){
 8     ll a;
 9     scanf("%lld%s",&a,s);
10     int n=strlen(s);
11     ll cnt=0;
12     for(int i=0;i<n;i++){
13         cnt+=(s[i]-'0');
14         int f=s[i]-'0';
15         v.push_back(9-f);
16     }
17     sort(v.begin(),v.end());
18     int ans=0;
19     while(cnt<a&&v.size()){
20         a-=v.back();
21         v.pop_back();
22         ans++;
23     }
24     cout<<ans<<endl;
25     return 0;
26 }

 

 

posted @ 2017-08-01 09:32  #忘乎所以#  阅读(291)  评论(0编辑  收藏  举报