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

34298번 - Closing Early 다국어

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

문제

Byron, the owner of a popular pizza shop renowned for its exclusive Hawaiian pizza, faces a unique challenge today. His shop operates on a strict policy: no pizza slices are wasted at the end of the day. Byron, an avid gamer, is eager to wrap up his day to play his favorite game, Hyper Space Pixel Conquerors (HSPC). However, he needs to ensure that he doesn't have any leftover pizza slices before he leaves.

At the start of the day, Byron's shop has exactly $R$ slices of Hawaiian pizza ready. Each whole pizza has exact $S$ slices of pizza. Throughout the day, $N$ customers will visit his shop in a sequential order. The $i^{\text{th}}$ customer will order $A_i$ slices of pizza. Byron, will prepare pizzas as necessary. That is, he will prepare an additional pizza only if he does not have enough slices of pizza ready to serve the current customer.

Byron's goal is to find the smallest number $k$ such that, after serving the first $k$ customers, he can close the shop without any pizza going to waste. The rest of the customers will be turned away. This occurs when the total number of pizza slices served, minus the initial $R$ slices, is exactly divisible by $S$. Formally, he wants to find the smallest number $k$ such that: \[ A_1 + A_2 + \ldots + A_k \equiv R \pmod{S}. \] Note that $k$ may be 0ドル$ if $R = 0$ and no customers should be served.

입력

The first line containing three space-separated integers $R,S,N$ (0ドル \leq R < S \leq 10^9,ドル 1ドル \leq N \leq 10^5$) --- the remaining slices at the start of the day, the number of slices in a single pizza, and the number of customers, respectively.

The second line contains $N$ integers, where the $i^{\text{th}}$ integer is $A_i$ (0ドル < A_i \leq 10^9$) --- the number of slices of pizza the $i^{\text{th}}$ customer will order.

출력

A single integer $k,ドル the smallest number such that, after serving $k$ customers, Byron will have no pizza left over. Note that it may be the case that $k=N$. If Byron cannot close the shop without leftovers, then output $-1$.

제한

예제 입력 1

7 10 5
2 1 4 12 6

예제 출력 1

3

예제 입력 2

0 7 3
1 2 3

예제 출력 2

0

예제 입력 3

5 9 7
4 2 1 3 3 6 3

예제 출력 3

-1

힌트

출처

School > CS@Mines > CS@Mines HSPC 2024 B번

  • 문제를 만든 사람: Kelly Dance
(追記) (追記ここまで)

출처

대학교 대회

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

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