#P14198. [ICPC 2024 Hangzhou R] Let's Go! New Adventure

[ICPC 2024 Hangzhou R] Let's Go! New Adventure

题目描述

In Pigeland, Pishin\textit{Pishin} is a popular open-world action RPG where users can play multiple characters. Each character has an independent adventure rank\textit{adventure rank}, which increases as they earn experience points (EXP) while being played. Initially, every character starts with an adventure rank of level 00 and can progress up to a maximum level of mm. To advance from level (i1)(i-1) to level ii (1im1 \leq i \leq m), the character is required to earn bib_i EXP. The higher the current rank, the more difficult it becomes to level up, meaning bibi+1b_i \leq b_{i+1} always holds for all ii from 11 to mm.

Grammy plans to play Pishin\textit{Pishin} for the next nn days. As a rich girl, her Pishin\textit{Pishin} account has an infinite number of characters. However, being a lazy girl, all characters in her account start with an adventure rank of level 00 at the beginning of the nn days. Each day, Grammy will select exactly one character to play, but once she stops playing a character, she cannot resume playing that character on any future day. In other words, she can only continue playing the same character on consecutive days.

On the ii-th day, Grammy will earn aia_i EXP for the character she plays. This means that if she plays a character continuously from the ll-th day to the rr-th day (both inclusive), the character's adventure rank will increase to level kk, where kk is the largest integer between 00 and mm such that the total EXP earned (which is i=lrai\sum\limits_{i=l}^r a_i) is greater than or equal to the requirement of leveling up to kk (which is i=1kbi\sum\limits_{i=1}^{k} b_i).

Being a greedy girl, Grammy wants to maximize the total sum of adventure ranks across all her characters after the nn days. However, as a single-minded girl, she doesn't want to play too many different characters. To balance this, she introduces a penalty factor of cc. Her goal is to maximize the total sum of adventure ranks across all characters after the nn days, minus c×dc \times d, where dd is the number of different characters she plays. As Grammy's best friend, your task is to compute the maximum value she can achieve under the optimal strategy for selecting characters.

输入格式

There are multiple test cases. The first line of the input contains an integer TT (1T5×1041 \leq T \leq 5 \times 10^4) indicating the number of test cases. For each test case:

The first line contains three integers nn, mm and cc (1n,m5×1051 \leq n,m \leq 5 \times 10^5, 0c5×1050 \leq c \leq 5 \times 10^5).

The second line contains nn integers a1,a2,,ana_1, a_2, \cdots, a_n (0ai10120 \leq a_i \leq 10^{12}, 0i=1nai10120 \le \sum\limits_{i = 1}^n a_i \leq 10^{12}).

The third line contains mm integers b1,b2,,bmb_1, b_2, \cdots, b_m (0bi10120 \leq b_i \leq 10^{12}, bibi+1b_i \leq b_{i+1}, 0i=1mbi10120 \leq \sum\limits_{i=1}^m b_i \leq 10^{12}).

It is guaranteed that neither the sum of nn nor the sum of mm of all test cases will exceed 5×1055 \times 10^5.

输出格式

For each test case, output one line containing one integer, indicating the maximum value.

2
5 4 2
1 0 3 1 2
0 1 1 2
4 5 1
7 16 23 4
1 3 6 20 20
3
6

提示

For the first sample test case, one solution is to use the first three days to get a character with adventure rank 44 and the next two days to get another character with adventure rank 33. This gives us a value of (42)+(32)=3(4-2)+(3-2)=3.

For the second sample test case, we can play a different character each day; this gives us adventure ranks 22, 33, 33, and 22, respectively. So the value is (21)+(31)+(31)+(21)=6(2-1)+(3-1)+(3-1)+(2-1)=6.