欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1946B.Maximum Sum
Maximum Sum
You have an array of integers.
You perform exactly operations on it. In one operation, you select any contiguous subarray of the array (possibly empty) and insert the sum of this subarray anywhere in the array.
Your task is to find the maximum possible sum of the array after such operations.
As this number can be very large, output the answer modulo .
Reminder: the remainder of a number modulo is the smallest non-negative such that there exists an integer and .
Input
Each test consists of several test cases. The first line contains a single integer () — the number of test cases. Then follows the description of the test cases.
The first line of each test case contains two integers and () — the length of the array and the number of operations, respectively.
The second line of each test case contains integers () — the array itself.
It is guaranteed that the sum of the values of and for all test cases does not exceed .
Output
For each test, output a single integer — the maximum sum of the array that can be obtained after operations modulo .
Note
In the first test case, it is advantageous to take an empty subarray of the array twice and insert the sum of the empty subarray (zero) anywhere, then the sum of the resulting array will be , modulo this is .
In the second test case, it is advantageous to take the sum of the entire array three times and place it anywhere in the array, then one of the possible sequences of actions: [] [] [] [], the sum of the final array is .
In the fourth test case, it is advantageous to take a subarray of the array consisting of the first three numbers (i.e. consisting of the numbers and ) and insert its sum at the beginning of the array, thereby obtaining the array [], the sum of this array is .
In the seventh test case, it will always be advantageous for us to take an empty subarray of the array. In this case, the sum of the resulting array will not differ from the sum of the original. The answer will be the sum of the original array, taken modulo — , because .
Samples
12
2 2
-4 -7
3 3
2 2 8
1 7
7
5 1
4 -2 8 -12 9
7 4
8 14 -9 6 0 -1 3
7 100
5 3 -8 12 -5 -9 3
6 1000
-1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000
2 1
1000000000 8
5 4
0 0 0 0 0
6 10
48973 757292 58277 -38574 27475 999984
7 1
-1000 1000 -1000 1000 -1000 1000 -1000
10 10050
408293874 -3498597 7374783 295774930 -48574034 26623784 498754833 -294875830 283045804 85938045
999999996
96
896
17
351
716455332
42
2
0
897909241
0
416571966
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |