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

33085번 - Stock Market 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 2048 MB56171426.923%

문제

Adrian owns a stock that he previously purchased, and wants to sell that stock. Currently, at day 0ドル,ドル the price of the stock is $P_0$. As a robot, Morgan can predict the future. Morgan tells Adrian that the price changes will repeat every $N$ days.

Formally, suppose that the price change from day $i$ to day $i + 1$ for 0ドル ≤ i ≤ N - 1$ is $D_i$. The price change from day $i$ to $i + 1$ for $i ≥ N$ is $D_i = D_{i \bmod N}$. The price of the stock at day $i$ for $i > 0$ is $P_i = P_{i-1} + D_{i-1}$. It is possible for a price to be negative.

Moreover, Morgan also knows that the price is on a downward trend. That is, the sum of all $D_i$ is negative.

The following table is the stock price of each day if $N = 6,ドル $P_0 = 20,ドル and $D_{0..5} = [4, -6, -1, 4, -9, -2]$.

Day 0ドル$ 1ドル$ 2ドル$ 3ドル$ 4ドル$ 5ドル$ 6ドル$ 7ドル$ 8ドル$ 9ドル$ 10ドル$ 11ドル$ 12ドル$ 13ドル$ 14ドル$ 15ドル$ 16ドル$ 17ドル$ $\dots$
Price 20ドル$ 24ドル$ 18ドル$ 17ドル$ 21ドル$ 12ドル$ 10ドル$ 14ドル$ 8ドル$ 7ドル$ 11ドル$ 2ドル$ 0ドル$ 4ドル$ $-2$ $-3$ 1ドル$ $-8$ $\dots$

Adrian can only sell the stock when the price is at least $X,ドル the price when he purchased the stock, to avoid any losses. As a thrill seeker, Adrian also would like to sell his stock at the lowest price possible while still being at least $X$.

Help Adrian to determine the lowest price of the stock that is not lower than $X,ドル or tell him if it is impossible. Note that Adrian can sell his stock at day 0ドル,ドル if $P_0 ≥ X$.

입력

Input begins with three integers $N$ $P_0$ $X$ (1ドル ≤ N ≤ 100,円 000$; 1ドル ≤ P_0, X ≤ 10^9$) representing the number of days in a cycle, the price at day 0ドル,ドル and the price when Adrian purchased the stock, respectively. The next line contains $N$ integers $D_i$ ($-10^9 ≤ D_i ≤ 10^9$) representing the price changes that repeat every $N$ days. It is guaranteed that the sum of all $D_i$ is negative.

출력

If a price not lower than $X$ exists, output an integer in a single line representing the lowest price of the stock that is not lower than $X$. Otherwise, output -1 in a single line.

제한

예제 입력 1

6 20 5
4 -6 -1 4 -9 -2

예제 출력 1

7

The table in the description represents this example. The lowest price of the stock that is not lower than 5ドル$ is $P_9 = 7$.

예제 입력 2

6 20 1
4 -6 -1 4 -9 -2

예제 출력 2

1

The lowest price of the stock that is not lower than 1ドル$ is $P_{16} = 1$.

예제 입력 3

1 3 4
-1

예제 출력 3

-1

The current price, $P_0,ドル is 3ドル$ and for any subsequent day, the price will never go up. Thus, it is impossible for the price to reach at least $X = 4$.

힌트

출처

ICPC > Regionals > Asia Pacific > Indonesia > Indonesia National Contest > INC 2022 F번

ICPC > Regionals > Asia Pacific > Indonesia > Indonesia National Contest > INC 2023 연습 세션 PC번

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

출처

대학교 대회

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

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