CF1920B.Summation Game

普及-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Alice and Bob are playing a game. They have an array a1,a2,…,ana_1, a_2,\ldots,a_n. The game consists of two steps:

  • First, Alice will remove at most kk elements from the array.
  • Second, Bob will multiply at most xx elements of the array by −1-1.

Alice wants to maximize the sum of elements of the array while Bob wants to minimize it. Find the sum of elements of the array after the game if both players play optimally.

爱丽丝和鲍勃正在玩一个游戏。他们有一个数组 a1,a2,…,ana_1, a_2,\ldots,a_n。游戏分为两个步骤:

  • 首先,爱丽丝最多从数组中删除 kk 个元素;
  • 然后,鲍勃最多将数组中的 xx 个元素乘以 −1-1。

爱丽丝希望最大化数组元素之和,而鲍勃希望最小化该和。若双方均采取最优策略,求游戏结束后数组元素的和。

输入格式

Each test consists of multiple test cases. The first line contains a single integer tt (1≤t≤1041 \leq t \leq 10^4) — the number of test cases. The description of the test cases follows.

The first line of each test case contains three integers nn, kk, and xx (1≤n≤2⋅1051 \leq n \leq 2 \cdot 10^5, 1≤x,k≤n1 \leq x,k \leq n) — the number of elements in the array, the limit on the number of elements of the array that Alice can remove, and the limit on the number of elements of the array that Bob can multiply −1-1 to.

The second line of each test case contains nn integers a1,a2,…,ana_1, a_2,\ldots, a_n (1≤ai≤10001 \leq a_i \leq 1000) — the elements of the array.

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

每个测试包含多个测试用例。第一行包含一个整数 tt(1≤t≤1041 \leq t \leq 10^4),表示测试用例的数量。随后是各测试用例的描述。

每个测试用例的第一行包含三个整数 nn、kk 和 xx(1≤n≤2⋅1051 \leq n \leq 2 \cdot 10^5,1≤x,k≤n1 \leq x,k \leq n)——分别表示数组中元素的个数、Alice 最多可删除的元素个数,以及 Bob 最多可将多少个元素乘以 −1-1。

每个测试用例的第二行包含 nn 个整数 a1,a2,…,ana_1, a_2,\ldots, a_n(1≤ai≤10001 \leq a_i \leq 1000)——表示数组的元素。

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

输出格式

For each test case, output a single integer — the sum of elements of the array after the game if both players play optimally.

对于每个测试用例,输出一个整数——即双方均采取最优策略进行游戏后,数组元素的总和。

输入输出样例

  • 输入#1

    8
    1 1 1
    1
    4 1 1
    3 1 2 4
    6 6 3
    1 4 3 2 5 6
    6 6 1
    3 7 3 3 32 15
    8 5 3
    5 5 3 3 3 2 9 9
    10 6 4
    1 8 2 9 3 3 4 5 3 200
    2 2 1
    4 3
    2 1 2
    1 3

    输出#1

    0
    2
    0
    3
    -5
    -9
    0
    -1

说明/提示

In the first test case, it is optimal for Alice to remove the only element of the array. Then, the sum of elements of the array is 00 after the game is over.

In the second test case, it is optimal for Alice to not remove any elements. Bob will then multiply 44 by −1-1. So the final sum of elements of the array is 3+1+2−4=23+1+2-4=2.

In the fifth test case, it is optimal for Alice to remove 9,99, 9. Bob will then multiply 5,5,35, 5, 3 by −1-1. So the final sum of elements of the array is −5−5−3+3+3+2=−5-5-5-3+3+3+2=-5.

在第一个测试用例中,Alice 最优的策略是移除数组中的唯一元素。游戏结束后,数组元素之和为 00。

在第二个测试用例中,Alice 最优的策略是不移除任何元素。随后 Bob 将 44 乘以 −1-1。因此,数组元素的最终和为 3+1+2−4=23+1+2-4=2。

在第五个测试用例中,Alice 最优的策略是移除 9,99, 9。随后 Bob 将 5,5,35, 5, 3 分别乘以 −1-1。因此,数组元素的最终和为 −5−5−3+3+3+2=−5-5-5-3+3+3+2=-5。

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

首页