

Time Limit: 2 sec / Memory Limit: 1024 MB
配点 : 点
問題文
高橋くんは人気ゲーム機「スヌケマシン」を買おうとしています。
スヌケマシンを販売している店は店 の 軒あり、店 は高橋くんの現在地から徒歩 分、スヌケマシンの販売価格は 円、現在のスヌケマシンの在庫は 台です。
高橋くんは今から徒歩でスヌケマシンを販売している店に向かい、店に着いたときにスヌケマシンの在庫があればスヌケマシンを買います。
しかし、スヌケマシンは人気商品なので、今から 分後に全ての店でスヌケマシンの在庫が (存在するなら) 台減ります。
高橋くんがスヌケマシンを買うことができるか判定し、できる場合は買うのに必要な最小の金額を求めてください。
制約
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
出力
高橋くんがスヌケマシンを買うことができる場合は、買うのに必要な最小の金額を出力せよ。
できない場合は、-1
を出力せよ。
入力例 1Copy
3 3 9 5 4 8 5 5 7 5
出力例 1Copy
8
店 に向かうと、高橋くんが着いたときにはスヌケマシンが 台残っていて、 円でスヌケマシンを買うことができます。
店 に向かうと、高橋くんが着いたときにはスヌケマシンが 台残っていて、 円でスヌケマシンを買うことができます。
店 に向かうと、高橋くんが着いたときにはスヌケマシンが売り切れていて、買うことができません。
入力例 2Copy
3 5 9 5 6 8 5 7 7 5
出力例 2Copy
-1
入力例 3Copy
10 158260522 877914575 602436426 24979445 861648772 623690081 433933447 476190629 262703497 211047202 971407775 628894325 731963982 822804784 450968417 430302156 982631932 161735902 880895728 923078537 707723857 189330739 910286918 802329211 404539679 303238506 317063340 492686568 773361868 125660016
出力例 3Copy
861648772
Score : points
Problem Statement
Takahashi wants to buy the popular video game console called Play Snuke.
There are shops that sell Play Snuke: Shop . Shop is minutes' walk from where Takahashi is now, sells Play Snuke for yen (Japanese currency), and currently has Play Snukes in stock.
Now, Takahashi will go to one of those shops on foot and buy Play Snuke if it is still in stock when he gets there.
However, Play Snuke is so popular that the number of consoles in stock (if any) in every shop will decrease by at the following moments: minutes from now.
Determine whether Takahashi can buy Play Snuke. If he can, find the minimum amount of money needed to buy one.
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
If Takahashi can buy Play Snuke, print the minimum amount of money needed to buy one, as an integer.
If he cannot buy one, print -1
.
Sample Input 1Copy
3 3 9 5 4 8 5 5 7 5
Sample Output 1Copy
8
If he goes to Shop , it will still have Play Snukes when he gets there, and he can buy one for yen.
If he goes to Shop , it will still have Play Snuke when he gets there, and he can buy one for yen.
If he goes to Shop , Play Snuke will be out of stock when he gets there; he cannot buy one.
Sample Input 2Copy
3 5 9 5 6 8 5 7 7 5
Sample Output 2Copy
-1
Sample Input 3Copy
10 158260522 877914575 602436426 24979445 861648772 623690081 433933447 476190629 262703497 211047202 971407775 628894325 731963982 822804784 450968417 430302156 982631932 161735902 880895728 923078537 707723857 189330739 910286918 802329211 404539679 303238506 317063340 492686568 773361868 125660016
Sample Output 3Copy
861648772