Logo
(追記) (追記ここまで)

16832번 - Additions 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 512 MB136650.000%

문제

You are given an integer $N$ and a string consisting of + and digits. You are asked to transform the string into a valid formula whose calculation result is smaller than or equal to $N$ by modifying some characters. Here, you replace one character with another character any number of times, and the converted string should still consist of + and digits. Note that leading zeros and unary positive are prohibited.

For instance, 0123+456 is assumed as invalid because leading zero is prohibited. Similarly, +1+2 and 2++3 are also invalid as they each contain a unary expression. On the other hand, 12345, 0+1+2 and 1234+0+0 are all valid.

Your task is to find the minimum number of the replaced characters. If there is no way to make a valid formula smaller than or equal to $N,ドル output $-1$ instead of the number of the replaced characters.

입력

The input consists of a single test case in the following format.

$N$
$S$

The first line contains an integer $N,ドル which is the upper limit of the formula (1ドル \le N \le 10^9$). The second line contains a string $S,ドル which consists of + and digits and whose length is between 1ドル$ and 1ドル{,}000,ドル inclusive. Note that it is not guaranteed that initially $S$ is a valid formula.

출력

Output the minimized number of the replaced characters. If there is no way to replace, output $-1$ instead.

제한

예제 입력 1

100
+123

예제 출력 1

2

예제 입력 2

10
+123

예제 출력 2

4

예제 입력 3

1
+123

예제 출력 3

-1

예제 입력 4

10
++1+

예제 출력 4

2

예제 입력 5

2000
1234++7890

예제 출력 5

2

힌트

In the first example, you can modify the first two characters and make a formula 1+23, for instance. In the second example, you should make 0+10 or 10+0 by replacing all the characters. In the third example, you cannot make any valid formula less than or equal to 1ドル$.

출처

Contest > ICPC Japanese Alumni Group > JAG Summer Camp > JAG Summer Camp 2018 Day 3 G번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /