A15735 | Remove the Bracket
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
RSJ has a sequence $a$ of $n$ integers $a_1,a_2, \ldots, a_n$ and an integer $s$ . For each of $a_2,a_3, \ldots, a_{n-1}$ , he chose a pair of non-negative integers $x_i$ and $y_i$ such that $x_i+y_i=a_i$ and $(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. $$ </p><p>Please help him find the minimum possible value $F$ he can get by choosing $x\_i$ and $y\_i$$$ optimally. It can be shown that there is always at least one valid way to choose them.
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. $$ </p><p>Please help him find the minimum possible value $F$ he can get by choosing $x\_i$ and $y\_i$$$ optimally. It can be shown that there is always at least one valid way to choose them.
输入格式
Each test contains multiple test cases. The first line contains an integer $t$ ( $1 \le t \le 10^4$ ) — the number of test cases.
The first line of each test case contains two integers $n$ , $s$ ( $3 \le n \le 2 \cdot 10^5$ ; $0 \le s \le 2 \cdot 10^5$ ).
The second line contains $n$ integers $a_1,a_2,\ldots,a_n$ ( $0 \le a_i \le 2 \cdot 10^5$ ).
It is guaranteed that the sum of $n$ does not exceed $2 \cdot 10^5$ .
The first line of each test case contains two integers $n$ , $s$ ( $3 \le n \le 2 \cdot 10^5$ ; $0 \le s \le 2 \cdot 10^5$ ).
The second line contains $n$ integers $a_1,a_2,\ldots,a_n$ ( $0 \le a_i \le 2 \cdot 10^5$ ).
It is guaranteed that the sum of $n$ does not exceed $2 \cdot 10^5$ .
输出格式
For each test case, print the minimum possible value of $F$ .
输入输出样例
输入 #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\cdot 0+0\cdot 1+0\cdot 3+0\cdot 4 = 0$ .
In the second test case, $5\cdot 1+2\cdot 2+2\cdot 2+1\cdot 5 = 18$ .
In the second test case, $5\cdot 1+2\cdot 2+2\cdot 2+1\cdot 5 = 18$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted