Codeforces Round 1067 (Div. 2)
C
Annoying Game
Codeforces
1400
原题
← BD →
翻译中…

You are given two integer arrays $a$ and $b$, both of length $n$, and a total number of turns $k$.

翻译中…

Alice and Bob play a game by taking turns modifying array $a$. Alice goes first. The game lasts for exactly $k$ turns.

翻译中…

On their turn, a player must choose an index $i$ ($1 \leq i \leq n$) and perform one of the following operations:

翻译中…
  • Add: Increase $a_i$ by $b_i$, i.e., set $a_i := a_i + b_i$.
  • Subtract: Decrease $a_i$ by $b_i$, i.e., set $a_i := a_i - b_i$.
翻译中…

After the $k$-th turn is complete, the final score is calculated as the maximum non-empty subarray sum of the modified array $a$. Alice's goal is to maximize the final score, while Bob's goal is to minimize the final score.

翻译中…

Assuming both players play optimally to achieve their respective goals, determine the final score.

翻译中…

The maximum non-empty subarray sum of $a$ is defined as $\max_{1 \leq i \leq j \leq n} S(i, j)$, where $S(i, j) = a_i + a_{i+1} + \cdots + a_j$. Note that empty subarrays are not considered.

翻译中…

Input

翻译中…

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.

翻译中…

The first line of each test case contains two integers $n$ and $k$ ($1 \le n \le 2\cdot 10^5$, $1 \le k \le 2\cdot 10^5$) — the length of the arrays and the total number of turns.

翻译中…

The second line contains $n$ integers $a_1,a_2,\ldots,a_{n}$ ($-10^9 \le a_i \le 10^9$) — the elements of array $a$.

翻译中…

The third line contains $n$ integers $b_1,b_2,\ldots,b_{n}$ ($0 \le b_i \le 10^9$) — the elements of array $b$.

翻译中…

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

翻译中…

Output

翻译中…

For each test case, print a single integer — the final score after $k$ turns, assuming both players play optimally.

翻译中…

Note

翻译中…

For the first test case:

翻译中…
  • Any move can't change the array $a$ because all elements in $b$ are zero.
  • The maximum non-empty subarray sum of this final array is $3 + (-1) + 9 = 11$.
翻译中…

For the second test case, one of the possible optimal sequences of moves is:

翻译中…
  • Alice adds $b_3=1$ to $a_3$. Array $a$ becomes $[10, 10, 11, 10]$.
  • Bob subtracts $b_1=1$ from $a_1$. Array $a$ becomes $[9, 10, 11, 10]$.
  • Alice adds $b_3=1$ to $a_3$. Array $a$ becomes $[9, 10, 12, 10]$.
  • Bob subtracts $b_1=1$ from $a_1$. Array $a$ becomes $[8, 10, 12, 10]$.
  • Alice adds $b_4=1$ to $a_4$. Array $a$ becomes $[8, 10, 12, 11]$.
  • The maximum non-empty subarray sum of this final array is $8+10+12+11 = 41$.
翻译中…

For the third test case, one of the possible optimal sequences of moves is:

翻译中…
  • Alice adds $b_2=11$ to $a_2$. Array $a$ becomes $[2, 4, 3]$.
  • The maximum non-empty subarray sum of this final array is $2 + 4 + 3 = 9$.
翻译中…

For the fourth test case, one of the possible optimal sequences of moves is:

翻译中…
  • Alice adds $b_2=11$ to $a_2$. Array $a$ becomes $[2, 4, 3]$.
  • Bob subtracts $b_2=11$ from $a_2$. Array $a$ becomes $[2, -7, 3]$.
  • The maximum non-empty subarray sum of this final array is $3$.
翻译中…

样例

Input #1
5
5 200000
3 -1 9 -5 4
0 0 0 0 0
4 5
10 10 10 10
1 1 1 1
3 1
2 -7 3
1 11 3
3 2
2 -7 3
1 11 3
1 1
-3
2
Output #1
11
41
9
3
-1
InputCopy OutputCopy
题目信息
题号
2158C
时间限制
2 s
内存限制
256 MB
标签
动态规划
博弈论
贪心

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。