【洛谷】AT_abc373_c [ABC373C] Max Ai+Bj 的题解
题解
题目大意:
给定两个长度为 N N N 的序列 A A A, B B B,求 A i + B j A_i + B_j Ai+Bj 的最大值。
那这样的话就很简单,只要在输入的时候找到 A A A 数组的最大值和 B B B 数组的最大值,然后分别将 A max A_{\max} Amax, B max B_{\max} Bmax 相加就可以了qaq。
不开 long long 见祖宗
代码
#include <bits/stdc++.h>
#define lowbit(x) x & (-x)
#define endl "\n"
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
namespace fastIO {
inline int read() {
register int x = 0, f = 1;
register char c = getchar();
while (c < '0' || c > '9') {
if(c == '-') f = -1;
c = getchar();
}
while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
return x * f;
}
inline void write(int x) {
if(x < 0) putchar('-'), x = -x;
if(x > 9) write(x / 10);
putchar(x % 10 + '0');
return;
}
}
using namespace fastIO;
ll n;
ll a, b, maxa = -1e9 - 7, maxb = -1e9 - 7;
int main() {
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n;
for(int i = 1; i <= n; i ++) {
cin >> a;
maxa = max(maxa, a);
}
for(int i = 1; i <= n; i ++) {
cin >> b;
maxb = max(maxb, b);
}
cout << maxa + maxb;
return 0;
}