#P1874. 快速求和
快速求和
Description
Given a numeric string, make it equal to a given target number using the minimum number of additions. Each addition means inserting a plus sign at some position in the string. After all required plus signs are inserted, evaluate it as ordinary addition.
For example, consider the string 12. With additions, we get the number . If we insert plus sign, we get . Therefore, in this case, the minimum number of additions to obtain the number is .
Another example: consider the string 303 and the target number . The optimal way is not 3+0+3, but 3+03. This works because a leading in a number does not change its value.
Input Format
The first line: a string .
The second line: an integer .
Output Format
Output a single integer on one line, the minimum number of additions to make equal to . If it is impossible to make equal to , output .
99999
45
4
Hint
Constraints
For of the testdata, it is guaranteed that , .
Translated by ChatGPT 5
京公网安备 11011102002149号