#P14198. [ICPC 2024 Hangzhou R] Let's Go! New Adventure
[ICPC 2024 Hangzhou R] Let's Go! New Adventure
题目描述
In Pigeland, is a popular open-world action RPG where users can play multiple characters. Each character has an independent , which increases as they earn experience points (EXP) while being played. Initially, every character starts with an adventure rank of level and can progress up to a maximum level of . To advance from level to level (), the character is required to earn EXP. The higher the current rank, the more difficult it becomes to level up, meaning always holds for all from to .
Grammy plans to play for the next days. As a rich girl, her account has an infinite number of characters. However, being a lazy girl, all characters in her account start with an adventure rank of level at the beginning of the 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 -th day, Grammy will earn EXP for the character she plays. This means that if she plays a character continuously from the -th day to the -th day (both inclusive), the character's adventure rank will increase to level , where is the largest integer between and such that the total EXP earned (which is ) is greater than or equal to the requirement of leveling up to (which is ).
Being a greedy girl, Grammy wants to maximize the total sum of adventure ranks across all her characters after the 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 . Her goal is to maximize the total sum of adventure ranks across all characters after the days, minus , where 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 () indicating the number of test cases. For each test case:
The first line contains three integers , and (, ).
The second line contains integers (, ).
The third line contains integers (, , ).
It is guaranteed that neither the sum of nor the sum of of all test cases will exceed .
输出格式
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 and the next two days to get another character with adventure rank . This gives us a value of .
For the second sample test case, we can play a different character each day; this gives us adventure ranks , , , and , respectively. So the value is .