CF1787C.Remove the Bracket

普及/提高-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

RSJ has a sequence aa of nn integers a1,a2,…,ana_1,a_2, \ldots, a_n and an integer ss. For each of a2,a3,…,an−1a_2,a_3, \ldots, a_{n-1}, he chose a pair of non-negative integers xix_i and yiy_i such that xi+yi=aix_i+y_i=a_i and (xi−s)⋅(yi−s)≥0(x_i-s) \cdot (y_i-s) \geq 0.

Now he is interested in the value $$F = a_1 \cdot x_2+y_2 \cdot x_3+y_3 \cdot x_4 + \ldots + y_{n - 2} \cdot x_{n-1}+y_{n-1} \cdot a_n.$$

Please help him find the minimum possible value FF he can get by choosing xix_i and yiy_i optimally. It can be shown that there is always at least one valid way to choose them.

RSJ 有一个由 nn 个整数 a1,a2,…,ana_1,a_2, \ldots, a_n 构成的序列 aa 和一个整数 ss。对于每个 a2,a3,…,an−1a_2,a_3, \ldots, a_{n-1},他选择了一对非负整数 xix_i 和 yiy_i,使得 xi+yi=aix_i+y_i=a_i 且 (xi−s)⋅(yi−s)≥0(x_i-s) \cdot (y_i-s) \geq 0。

现在他关心如下表达式的值:

F=a_1cdotx_2+y_2cdotx_3+y_3cdotx_4+ldots+y_n−2cdotx_n−1+y_n−1cdota_n.F = a\_1 \\cdot x\_2+y\_2 \\cdot x\_3+y\_3 \\cdot x\_4 + \\ldots + y\_{n - 2} \\cdot x\_{n-1}+y\_{n-1} \\cdot a\_n.

请帮助他找出通过最优选择 xix_i 和 yiy_i 所能得到的 FF 的最小可能值。可以证明,总存在至少一种合法的方式选择这些数。

输入格式

Each test contains multiple test cases. The first line contains an integer tt (1≤t≤1041 \le t \le 10^4) — the number of test cases.

The first line of each test case contains two integers nn, ss (3≤n≤2⋅1053 \le n \le 2 \cdot 10^5; 0≤s≤2⋅1050 \le s \le 2 \cdot 10^5).

The second line contains nn integers a1,a2,…,ana_1,a_2,\ldots,a_n (0≤ai≤2⋅1050 \le a_i \le 2 \cdot 10^5).

It is guaranteed that the sum of nn does not exceed 2⋅1052 \cdot 10^5.

每个测试包含多个测试用例。第一行包含一个整数 tt(1≤t≤1041 \le t \le 10^4),表示测试用例的数量。

每个测试用例的第一行包含两个整数 nn、ss(3≤n≤2⋅1053 \le n \le 2 \cdot 10^5;0≤s≤2⋅1050 \le s \le 2 \cdot 10^5)。

第二行包含 nn 个整数 a1,a2,…,ana_1,a_2,\ldots,a_n(0≤ai≤2⋅1050 \le a_i \le 2 \cdot 10^5)。

保证所有测试用例的 nn 之和不超过 2⋅1052 \cdot 10^5。

输出格式

For each test case, print the minimum possible value of FF.

对于每个测试用例,输出 FF 的最小可能值。

输入输出样例

  • 输入#1

    10
    5 0
    2 0 1 3 4
    5 1
    5 3 4 3 5
    7 2
    7 6 5 4 3 2 1
    5 1
    1 2 3 4 5
    5 2
    1 2 3 4 5
    4 0
    0 1 1 1
    5 5
    4 3 5 6 4
    4 1
    0 2 1 0
    3 99999
    200000 200000 200000
    6 8139
    7976 129785 12984 78561 173685 15480

    输出#1

    0
    18
    32
    11
    14
    0
    16
    0
    40000000000
    2700826806

说明/提示

In the first test case, 2⋅0+0⋅1+0⋅3+0⋅4=02\cdot 0+0\cdot 1+0\cdot 3+0\cdot 4 = 0.

In the second test case, 5⋅1+2⋅2+2⋅2+1⋅5=185\cdot 1+2\cdot 2+2\cdot 2+1\cdot 5 = 18.

在第一个测试用例中,2⋅0+0⋅1+0⋅3+0⋅4=02\cdot 0+0\cdot 1+0\cdot 3+0\cdot 4 = 0。

在第二个测试用例中,5⋅1+2⋅2+2⋅2+1⋅5=185\cdot 1+2\cdot 2+2\cdot 2+1\cdot 5 = 18。

输入解题思路,AI测评打分。不知道怎么写?

首页