#abc348g. G - Max (Sum - Max)
G - Max (Sum - Max)
Score: points
问题陈述
给定两个整数序列 和 ,它们的长度都是 。对于 ,解决以下问题:
- 考虑在 到 (包括 和 )之间选择 个不同的整数。设 是所选整数的集合。找到 $\displaystyle (\sum_{i \in S} A_i) - \max_{i \in S} B_i$ 的最大值。
以上为大语言模型 kimi 翻译,仅供参考。
Problem Statement
You are given two integer sequences and of length . For , solve the following problem:
- Consider choosing distinct integers between and , inclusive. Let be the set of chosen integers. Find the maximum value of $\displaystyle (\sum_{i \in S} A_i) - \max_{i \in S} B_i$.
Constraints
Input
The input is given from Standard Input in the following format:
Output
Print lines. The -th line should contain the answer to the problem for .
Sample Input 1
3
4 1
5 6
3 2
Sample Output 1
3
5
6
The following choices are optimal.
- :
- :
- :
Sample Input 2
2
0 1
0 1
Sample Output 2
-1
-1
Sample Input 3
6
9 7
2 4
7 1
-1000 0
3 4
8 5
Sample Output 3
6
10
17
20
22
-978