#abc231e. E - Minimal payments

E - Minimal payments

Score : 500500 points

问题描述

在Atcoder王国中,有NN种硬币:A1A_1日元、A2A_2日元、\ldotsANA_N日元硬币。 这里满足条件 1=A1<<AN1=A_1 < \ldots < A_N,并且对于任意的 1iN11\leq i \leq N-1,都有 Ai+1A_{i+1}AiA_i 的倍数。

当仅使用这些硬币支付价值为 XX 日元的商品时,付款及找零所需的最小总硬币数量是多少?

准确地说,当 YY 是大于等于 XX 的整数时,求表示正好 YY 日元所需硬币数量与表示正好 YXY-X 日元所需硬币数量之和的最小值。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

There are NN kinds of coins used in the Kingdom of Atcoder: A1A_1-yen, A2A_2-yen, \ldots, ANA_N-yen coins.
Here, 1=A1<<AN1=A_1 < \ldots < A_N holds, and Ai+1A_{i+1} is a multiple of AiA_i for every 1iN11\leq i \leq N-1.

When paying for a product worth XX yen using just these coins, what is the minimum total number of coins used in payment and returned as change?

Accurately, when YY is an integer at least XX, find the minimum sum of the number of coins needed to represent exactly YY yen and the number of coins needed to represent exactly YXY-X yen.

Constraints

  • All values in input are integers.
  • 1N601 \leq N \leq 60
  • 1=A1<<AN10181=A_1 < \ldots <A_N \leq 10^{18}
  • Ai+1A_{i+1} is a multiple of AiA_i for every 1iN11\leq i \leq N-1.
  • 1X10181\leq X \leq 10^{18}

Input

Input is given from Standard Input in the following format:

NN XX

A1A_1 \ldots ANA_N

Output

Print the answer.

Sample Input 1

3 87
1 10 100

Sample Output 1

5

If we pay with one 100100-yen coin and receive one 1010-yen coin and three 11-yen coins as the change, the total number of coins will be 55.

Sample Input 2

2 49
1 7

Sample Output 2

7

It is optimal to pay with seven 77-yen coins.

Sample Input 3

10 123456789012345678
1 100 10000 1000000 100000000 10000000000 1000000000000 100000000000000 10000000000000000 1000000000000000000

Sample Output 3

233

update @ 2024/3/10 10:05:01

}