CF2239B.Decidophobia
普及/提高-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
There are n people attending a round-table party, numbered 1,2,3,…,n in clockwise order. You have prepared some gifts to distribute among them.
Each person i has a weight ai 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).
The happiness gained by person i is determined by the following rules:
- 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⋅ai 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⋅ai happiness.
You want to maximize the total happiness of all n people combined. Find this maximum value.
有 n 个人参加一场圆桌宴会,按顺时针方向编号为 1,2,3,…,n。你已准备了一些礼物分发给他们。
每个人 i 有一个权重 ai 和一个公共视野范围 d。第 i 个人的视野范围包括其顺时针方向的 d 个人以及逆时针方向的 d 个人(共 2d 人,不包含 i 自身)。
第 i 个人所获得的幸福感由以下规则决定:
- 若第 i 个人收到礼物,且其视野范围内有 x 个人未收到礼物,则其获得 x⋅ai 的幸福感;
- 若第 i 个人未收到礼物,且其视野范围内有 x 个人收到了礼物,则其产生 −x⋅ai 的幸福感(即损失 x⋅ai 的幸福感)。
你希望最大化所有 n 个人的总幸福感。求该最大值。
输入格式
Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤104). The description of the test cases follows.
The first line of each test case contains two integers n and d (3≤n≤2⋅105, 1≤d<2n).
The second line contains n integers a1,a2,…,an (1≤ai≤108), where ai is the weight of the i-th person.
It is guaranteed that the sum of n over all test cases does not exceed 106.
每个测试包含多个测试用例。第一行包含测试用例的数量 t(1≤t≤104)。随后是各测试用例的描述。
每个测试用例的第一行包含两个整数 n 和 d(3≤n≤2⋅105,1≤d<2n)。
第二行包含 n 个整数 a1,a2,…,an(1≤ai≤108),其中 ai 表示第 i 个人的体重。
保证所有测试用例中 n 的总和不超过 106。
输出格式
For each test case, output a single integer representing the maximum total happiness.
对于每个测试用例,输出一个整数,表示最大总幸福感。
输入输出样例
输入#1
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
输出#1
3 15 26 8590 0
说明/提示
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⋅a2=2⋅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.
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.
在第一个测试用例中,有 3 个人围成一圈就坐。对每个人 i,其视野范围为 d=1,即包括其顺时针方向的 1 个人和逆时针方向的 1 个人。若将礼物送给第 2 个人,则其因获得礼物而从 2 个未收到礼物的邻居处获得幸福感,贡献值为 2⋅a2=2⋅2=4。然而,第 1 个人和第 3 个人会遭受损失,因为他们未收到礼物,但各自有一个收到礼物的邻居。在计算所有可能情况后,总幸福感的最大值为 3。
在第二个测试用例中,n=5,d=1。最优方案是将礼物送给第 2、第 3 和第 5 个人,此时可达到总幸福感的最大值 15。
输入解题思路,AI测评打分。不知道怎么写?