决策恐惧症AI (CI翻译)
There are $n$ people attending a round-table party, numbered $1, 2, 3, \ldots, n$ in clockwise order. You have prepared some gifts to distribute among them.
有 $n$ 个人参加一场圆桌派对,他们按顺时针方向编号为 $1, 2, 3, \ldots, n$。你准备了一些礼物,打算分发给他们。AI (CI翻译)
Each person $i$ has a weight $a_i$ and a common field of view $d$. The field of view for person $i$ consists of the $d$ people sitting clockwise and the $d$ people sitting counter-clockwise from them (a total of $2d$ people excluding person $i$).
每个人 $i$ 有一个权重 $a_i$,所有人的视野范围相同,均为 $d$。对于每个人,其视野范围包括顺时针方向相邻的 $d$ 个人和逆时针方向相邻的 $d$ 个人(不包括本人,共 $2d$ 个人)。AI (CI翻译)
The happiness gained by person $i$ is determined by the following rules:
每个人获得的快乐值由以下规则决定:AI (CI翻译)
- If person
$i$receives a gift, and there are$x$people within their field of view who did not receive a gift, they gain$x \cdot a_i$happiness. - If person
$i$does not receive a gift, and there are$x$people within their field of view who received a gift, they incur$-x \cdot a_i$happiness.
- 如果一个人收到了礼物,且其视野范围内有
$x$个人没有收到礼物,那么他的快乐值增加$x \cdot a_i$。 - 如果一个人没有收到礼物,且其视野范围内有
$x$个人收到了礼物,那么他的快乐值减少$x \cdot a_i$。
You want to maximize the total happiness of all $n$ people combined. Find this maximum value.
你想最大化所有 $n$ 个人的快乐值总和。请求出这个最大值。AI (CI翻译)
Input
输入格式
AI (CI翻译)Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^4$). The description of the test cases follows.
每个输入包含多组测试用例。第一行包含测试用例数量 $t$($1 \le t \le 10^4$)。接下来是各测试用例的描述。AI (CI翻译)
The first line of each test case contains two integers $n$ and $d$ ($3 \le n \le 2 \cdot 10^5$, $1 \le d \lt \frac{n}{2}$).
每个测试用例的第一行包含两个整数 $n$ 和 $d$($3 \le n \le 2 \cdot 10^5$,$1 \le d \lt \frac{n}{2}$)。AI (CI翻译)
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^8$), where $a_i$ is the weight of the $i$-th person.
第二行包含 $n$ 个整数 $a_1, a_2, \ldots, a_n$($1 \le a_i \le 10^8$),其中 $a_i$ 表示第 $i$ 个人的权重。AI (CI翻译)
It is guaranteed that the sum of $n$ over all test cases does not exceed $10^6$.
保证所有测试用例中 $n$ 的总和不超过 $10^6$。AI (CI翻译)
Output
输出格式
AI (CI翻译)For each test case, output a single integer representing the maximum total happiness.
对于每个测试用例,输出一个整数,表示快乐值总和的最大值。AI (CI翻译)
Note
说明
AI (CI翻译)In the first test case, there are 3 people sitting in a circle. For each person $i$, the field of view is $d=1$, which includes the 1 person sitting clockwise and the 1 person sitting counter-clockwise from them. If person 2 receives the gift, they gain happiness from 2 neighbors who did not receive it, resulting in $2 \cdot a_2 = 2 \cdot 2 = 4$. However, person 1 and person 3 incur loss because they did not receive a gift but have a neighbor who did. After calculating all possibilities, the maximum total happiness is 3.
在第一个测试用例中,圆桌旁有 3 个人。对于每个人 $i$,其视野范围为 $d=1$,包括顺时针方向和逆时针方向各相邻的 1 个人。如果给 2 号送礼物,那么他会从 2 个没有收到礼物的邻居那里获得快乐值,即 $2 \cdot a_2 = 2 \cdot 2 = 4$。然而,1 号和 3 号没有收到礼物,但他们各自有一个邻居收到了礼物,因此会损失快乐值。计算所有可能情况后,最大快乐值为 3。AI (CI翻译)
In the second test case, $n=5, d=1$. The best solution is to give gifts to persons 2, 3, and 5, which can achieve the maximum total happiness value of 15.
在第二个测试用例中,$n=5, d=1$。最优方案是给 2、3、5 号送礼物,此时快乐值总和最大为 15。AI (CI翻译)
样例
5
3 1
1 2 3
5 1
1 4 5 2 6
6 2
1 1 4 5 1 4
10 2
230 24 3 42 432 234 934 2389 333 444
3 1
100000000 100000000 100000000
3
15
26
8590
0
题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。