A16382 | Summation Game
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Alice and Bob are playing a game. They have an array $a_1, a_2,\ldots,a_n$ . The game consists of two steps:
- First, Alice will remove at most $k$ elements from the array.
- Second, Bob will multiply at most $x$ elements of the array by $-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.
- First, Alice will remove at most $k$ elements from the array.
- Second, Bob will multiply at most $x$ elements of the array by $-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.
输入格式
Each test consists of multiple test cases. The first line contains a single integer $t$ ( $1 \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 $n$ , $k$ , and $x$ ( $1 \leq n \leq 2 \cdot 10^5$ , $1 \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$ to.
The second line of each test case contains $n$ integers $a_1, a_2,\ldots, a_n$ ( $1 \leq a_i \leq 1000$ ) — the elements of the array.
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$ .
The first line of each test case contains three integers $n$ , $k$ , and $x$ ( $1 \leq n \leq 2 \cdot 10^5$ , $1 \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$ to.
The second line of each test case contains $n$ integers $a_1, a_2,\ldots, a_n$ ( $1 \leq a_i \leq 1000$ ) — the elements of the array.
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \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 $0$ after the game is over.
In the second test case, it is optimal for Alice to not remove any elements. Bob will then multiply $4$ by $-1$ . So the final sum of elements of the array is $3+1+2-4=2$ .
In the fifth test case, it is optimal for Alice to remove $9, 9$ . Bob will then multiply $5, 5, 3$ by $-1$ . So the final sum of elements of the array is $-5-5-3+3+3+2=-5$ .
In the second test case, it is optimal for Alice to not remove any elements. Bob will then multiply $4$ by $-1$ . So the final sum of elements of the array is $3+1+2-4=2$ .
In the fifth test case, it is optimal for Alice to remove $9, 9$ . Bob will then multiply $5, 5, 3$ by $-1$ . So the final sum of elements of the array is $-5-5-3+3+3+2=-5$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted