题目大意
给定长度为 NNN 的序列 AAA 和 BBB,求 Ai+BjA_i+B_jAi+Bj 的最大值。
题目思路
水。
需要最大值,只需要 AiA_iAi 和 BjB_jBj 都尽可能大,所以只要找到序列 AAA 和 BBB 的最大值求和即可。
Code
#include <iostream>
using namespace std;
signed main() {
ios::sync_with_stdio(false), cin.tie(), cout.tie();
int n, a;
cin >> n;
int max1 = -2000000000, max2 = -2000000000;//赋初值
for (int i = 0; i < n; ++i) cin >> a, max1 = max(max1, a);//找 A 的最大值
for (int i = 0; i < n; ++i) cin >> a, max2 = max(max2, a);//找 B 的最大值
cout << max1 + max2;//输出和
return 0;
}