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

33010번 - Peculiar Protocol 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 2048 MB55111125.581%

문제

The Kingdom of Icpca has a peculiar protocol in wedding ceremonies. That is, amounts of monetary gifts should be a multiple of a fixed quantity plus a fixed extra. When the fixed quantity is $d$ and the fixed extra is $r,ドル courteous amounts of wedding gifts are $k \times d + r$ for any non-negative integer multipliers $k$.

Initially, you have a pile of $n$ banknotes. Every time you attend a wedding ceremony, you draw out a contiguous portion from your current banknote pile as your gift that sums up to a courteous amount, that is, a multiple of $d$ plus additional $r$. If no contiguous portion sums up to such an amount, you cannot attend wedding ceremonies any more. After drawing out, the remaining banknotes are squeezed to form a single pile, keeping their relative order. The resultant pile of banknotes may have portions with such an amount, which allows you to attend more ceremonies.

Your monetary gifts are expected to raise your social reputation. As the additional amount $r$ is considered mandatory, the multiplier $k$ is considered significant. Your reputation is raised in proportion to $k$ at each of the ceremonies you attend.

For example, assume $d = 5$ and $r = 1,ドル and you have banknotes whose values are 2ドル,ドル 2ドル,ドル 2ドル,ドル 4ドル,ドル and 4ドル,ドル piled up in this order. When you attend a wedding ceremony, there are following two possible ways to give courteous monetary gifts.

  • Give a monetary gift consisting of the first three banknotes from the top, totaling 2ドル + 2 + 2 = 6 = 1\times d+r$. After drawing them out, you have banknotes with values 4ドル$ and 4ドル$. No contiguous portion of your remaining banknote pile sums up to a courteous amount. Thus, you cannot attend wedding ceremonies anymore.
  • Give a monetary gift consisting of the third and the fourth banknotes, totaling 2ドル+4 = 6 = 1 \times d+r$. After drawing them out, you have banknotes with values 2ドル,ドル 2ドル,ドル and 4ドル,ドル in this order. You can attend another wedding ceremony because the second and the third banknotes total 2ドル+4 = 6 = 1 \times d+r,ドル which is courteous.

In this example, the second way can maximize your social reputation by attending two ceremonies, because the total of the multipliers is 1ドル + 1 = 2,ドル which achieves the maximum possible.

In contrast, if the value of the first banknote is 12ドル,ドル giving the first three banknotes at a ceremony prevents you from attending more ceremonies. That, however, maximizes your social reputation because the total of the multipliers is 3ドル,ドル which achieves the maximum possible.

Compute the maximum possible total of the multipliers with your monetary gifts at wedding ceremonies. You may assume that you have so many unmarried relatives and friends that you can attend any number of wedding ceremonies as long as you can give courteous monetary gifts.

입력

The input consists of a single test case in the following format.

$n$ $d$ $r$

$a_1$ $\cdots$ $a_n$

The first line has three integers $n,ドル $d,ドル and $r$. The integer $n$ (1ドル ≤ n ≤ 500$) is the number of banknotes you have. The integers $d$ and $r$ (2ドル ≤ d ≤ 10^8,ドル 0ドル ≤ r < d$) represent the parameters of the peculiar protocol. The second line has $n$ integers, $a_1, \dots , a_n$. Here, $a_i$ (0ドル ≤ a_i ≤ 10^8$) represents the value of the banknote $i$-th from the top.

출력

Output a line containing the maximum possible total of the multipliers with your monetary gifts at wedding ceremonies.

제한

예제 입력 1

5 5 1
2 2 2 4 4

예제 출력 1

2

예제 입력 2

5 5 1
12 2 2 4 4

예제 출력 2

3

예제 입력 3

5 20000 10000
5000 10000 15000 5000 25000

예제 출력 3

2

예제 입력 4

9 5 3
4 2 2 1 1 4 3 2 1

예제 출력 4

2

힌트

출처

ICPC > Regionals > Asia Pacific > Japan > 2024 ICPC Asia Yokohama Regional Contest L번

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

출처

대학교 대회

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

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