forked from anandadfoxx/codeforces_solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
1469B.cpp
47 lines (37 loc) · 888 Bytes
/
1469B.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <bits/stdc++.h>
#define FOR(i, start, end) for(int i = start; i < end; i++)
using namespace std;
typedef long long LL;
int n, m, maxs, dp[105][105], r[105], b[105];
void calc(int rI, int bI) {
if (rI > n || bI > m) return;
if (rI == 0 && bI == 0) dp[rI][bI] = 0;
if (dp[rI+1][bI] == -1) {
dp[rI+1][bI] = dp[rI][bI] + r[rI];
calc(rI+1, bI);
}
if (dp[rI][bI+1] == -1) {
dp[rI][bI+1] = dp[rI][bI] + b[bI];
calc(rI, bI+1);
}
maxs = max(maxs, max(dp[rI+1][bI], dp[rI][bI+1]));
}
void solve() {
memset(r, 0, sizeof(r));
memset(b, 0, sizeof(b));
cin >> n;
FOR(i, 0, n)
cin >> r[i];
cin >> m;
FOR(i, 0, m)
cin >> b[i];
maxs = 0;
memset(dp, -1, sizeof(dp));
calc(0, 0);
cout << maxs << '\n';
}
int main() {
int t;
cin >> t;
while (t--) solve();
}