Stock Market
시간 제한1초메모리 제한2048 MB
주기적으로 반복되는 주가가 장기적으로 하락할 때, X 이상이면서 가장 낮은 가격을 찾는다. 없으면 -1을 출력한다.
문제
Adrian owns a stock that he previously purchased, and wants to sell that stock. Currently, at day , the price of the stock is . As a robot, Morgan can predict the future. Morgan tells Adrian that the price changes will repeat every days.
Formally, suppose that the price change from day to day for is . The price change from day to for is . The price of the stock at day for is . 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 is negative.
The following table is the stock price of each day if , , and .
Adrian can only sell the stock when the price is at least , 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 .
Help Adrian to determine the lowest price of the stock that is not lower than , or tell him if it is impossible. Note that Adrian can sell his stock at day , if .
입력
Input begins with three integers (; ) representing the number of days in a cycle, the price at day , and the price when Adrian purchased the stock, respectively. The next line contains integers () representing the price changes that repeat every days. It is guaranteed that the sum of all is negative.
출력
If a price not lower than exists, output an integer in a single line representing the lowest price of the stock that is not lower than . Otherwise, output -1 in a single line.