#abc302d. D - Impartial Gift
D - Impartial Gift
Score : points
问题描述
Takahashi 已决定给 Aoki 和 Snuke 各赠送 一件 礼物。
对于 Aoki,有 件候选礼物,它们的价值分别为 。
对于 Snuke,有 件候选礼物,它们的价值分别为 。
Takahashi 希望选择一对礼物,使得两件礼物的价值差不超过 。
判断他是否可以选出满足条件的一对礼物。如果可以,则输出所选礼物价值之和的最大值。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
Takahashi has decided to give one gift to Aoki and one gift to Snuke.
There are candidates of gifts for Aoki, and their values are .
There are candidates of gifts for Snuke, and their values are .
Takahashi wants to choose gifts so that the difference in values of the two gifts is at most .
Determine if he can choose such a pair of gifts. If he can, print the maximum sum of values of the chosen gifts.
Constraints
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
Output
If he can choose gifts to satisfy the condition, print the maximum sum of values of the chosen gifts. If he cannot satisfy the condition, print .
Sample Input 1
2 3 2
3 10
2 5 15
Sample Output 1
8
The difference of values of the two gifts should be at most .
If he gives a gift with value to Aoki and another with value to Snuke, the condition is satisfied, achieving the maximum possible sum of values.
Thus, should be printed.
Sample Input 2
3 3 0
1 3 3
6 2 7
Sample Output 2
-1
He cannot choose gifts to satisfy the condition. Note that the candidates of gifts for a person may contain multiple gifts with the same value.
Sample Input 3
1 1 1000000000000000000
1000000000000000000
1000000000000000000
Sample Output 3
2000000000000000000
Note that the answer may not fit into a -bit integer type.
Sample Input 4
8 6 1
2 5 6 5 2 1 7 9
7 2 5 5 2 4
Sample Output 4
14
update @ 2024/3/10 08:29:31