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

17600번 - Change Making 다국어

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

문제

The change-making problem is a classical competitive programming problem. The problem is about a currency system. In this system, there are n available denominations of coins \$c1, \$c2, . . . , \$cn where c1 = 1 and c2, . . . , cn are all integers. Assume you can have unlimited supply of each denomination of coins. The change-making problem is: given a target x, make a change of \$x with minimum number of coins.

The change-making problem has appeared so many times in programming contest. Many contestants know how to solve this problem. However, there are also many contestants doing it wrongly. For example, many of them use greedy algorithm which does not work. This greedy algorithm repeatedly takes the coin with greatest value which does not exceed x. This algorithm actually works for some currency system but not for this case: \1,ドル \3,ドル \4ドル and the target x = 6. We call such case a counterexample to this greedy algorithm, and x = 6 is a witness of the currency system \1,ドル \3,ドル \4ドル.

Please write a program to find the minimum witness for a given currency system. If there does not exist a witness or the minimum witness is greater than 105, your program should output −1.

입력

The first line contains an integer n to indicate the number of denominations in the currency system. The second line contains n integers c1, . . . , cn where the currency system has \$c1, . . . , \$cn.

출력

Output the minimum witness x if x ≤ 105. Otherwise output −1.

제한

  • n ≤ 50
  • c1 = 1 < c2 < · · · < cn ≤ 105

예제 입력 1

3
1 3 4

예제 출력 1

6

예제 입력 2

5
1 5 10 20 50

예제 출력 2

-1

힌트

출처

ICPC > Regionals > Asia Pacific > Taiwan > Taiwan Online Programming Contest > TOPC 2019 C번

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

출처

대학교 대회

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

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