umetanje
You are given numbers n and k. You are allowed to insert + between the digits of the number n. This way you obtain an expression. The goal is to insert + between the digits of n so that the value of the obtained expression is as close as possible to k (by close we mean that the absolute difference is as low as possible)
InputTwo integers n and k (1 <= n, k <= 10^9).
OutputWrite the value of the expression obtained by adding + signs among the digits of n.
Input:
Output:
Explanation:
We insert the + signs between the digits of n the following way: 1 + 996 + 7 = 1004, and that is the number closest to 1000.
19967 1000Output:
1004Explanation:
We insert the + signs between the digits of n the following way: 1 + 996 + 7 = 1004, and that is the number closest to 1000.
Image: umetanje_ex.png
Submit solution
Coming laterThe grading service will be connected in a later migration step. You can inspect the task and your previous results now.