問題一覧 > 通常問題

No.3433 [Cherry 8th Tune A] ADD OIL!

レベル : / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (解説公開後に AC するまで非表示) / 解いたユーザー数 90
作問者 : 👑 Kazun / テスター : kazuppa
お気に入りにしたユーザー ProblemId : 10723 / 自分の提出
問題文最終更新日: 2026-01-23 00:37:55
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 491 Go on Back!! (順位表) の他の問題:

Problem Visual

▶ The problem visual is revealed when the contest opens

Problem Statement

There is a machine consisting of $N$ gears. The cost of the $i~(1 \leq i \leq N)$-th gear is $A_i$. The cost of this machine is defined as the total product (multiplication) of the $N$ gears.

Cherry has some lubricating oil. Using this oil on a gear in the machine lowers the cost of that gear by $K$. However, this oil can only be used on $1$ gear.

Find the minimum possible cost of the machine after using the oil.

Solve $T$ test cases.

Constraints

  • $1 \leq T \leq 100$.
  • Constraints for each test case
    • $2 \leq N \leq 8$.
    • $1 \leq K \lt 100$.
    • $K \lt A_i \leq 100 \quad (1 \leq i \leq N)$.
  • All input values are integers.

Input

The input is given from standard input in the following format.

$T$
${\rm Testcase}_1$
$\vdots$
${\rm Testcase}_T$

Each test case is given in the following format.

$N$ $K$
$A_1$ $A_2$ $\dots$ $A_N$

Output

The output consists of $T$ lines. On the $t~(1 \leq t \leq T)$-th line, print the answer to the $t$-th test case as an integer.

Do not forget the newline at the end.

Sample

Sample 1
Input
3
3 5
10 20 30
6 99
100 100 100 100 100 100
2 1
3 23
Output
3000
10000000000
46

[About the $1$-st test case]

The machine has $3$ gears. The change in the cost of the machine when the oil is used on each gear is as follows.

  • If the oil is used on the $1$-st gear, the cost of the $1$-st gear becomes $10 - 5 = 5$. Therefore, the cost of the machine becomes $5 \times 20 \times 30 = 3000$.
  • If the oil is used on the $2$-nd gear, the cost of the $2$-nd gear becomes $20 - 5 = 15$. Therefore, the cost of the machine becomes $10 \times 15 \times 30 = 4500$.
  • If the oil is used on the $3$-rd gear, the cost of the $3$-rd gear becomes $30 - 5 = 25$. Therefore, the cost of the machine becomes $10 \times 20 \times 25 = 5000$.

From the above, the cost of the machine is minimized when the oil is used on the $1$-st gear, and the cost in that case is $3000$.

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。