-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path296329512
148 lines (137 loc) · 3.06 KB
/
296329512
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#include<bits/stdc++.h>
using namespace std;
#define FELIX
#define ll long long int
#define vi vector<ll>
#define ip(v,n) for(ll i=0;i<n;i++)cin>>v[i];
#define op(v,n) for(ll i=0;i<n;i++)cout<<v[i]<<" ";
#define opp(v,n) for(ll i=0;i<n;i++)cout<<v[i].first<<" "<<v[i].second<<endl;
#define all(x) x.begin(),x.end()
#define srt(x) sort(all(x))
#define cl(a,b) ceil(a/(double)b)
#define fors(n) for(ll i=0;i<n;i++)
long long binaryExponentiation(long long base, long long exponent) {
long long result = 1;
while (exponent > 0) {
if (exponent % 2 == 1) {
result *= base; // If exponent is odd, multiply the result by the base
}
base *= base; // Square the base
exponent /= 2; // Divide the exponent by 2
}
return result;
}
bool checkprime(ll n) {
if (n <= 1) return false;
if (n <= 3) return true;
if (n % 2 == 0 || n % 3 == 0) return false;
for (ll i = 5; i * i <= n; i += 6) {
if (n % i == 0 || n % (i + 2) == 0) return false;
}
return true;
}
vi getFactorization(ll n) {
vi factors;
for (ll i = 2; i * i <= n; ++i) {
if (n % i == 0) {
factors.push_back(i);
if (i != n / i) {
factors.push_back(n / i);
}
}
}
return factors;
}
bool check_if_no_is_in_2_ki_power_any_x(ll n){
if(!(n&(n-1)))return false;
return true;
}
vector<ll>findpro(ll n){
vector<ll>result;
ll d=2;
while(d*d<=n||n!=1){
if(n%d==0){
result.push_back(d);
n=n/d;
}else{
while(n%d!=0)d++;
}
}
return result;
}
ll gcd(ll a,ll b) {
while (b != 0) {
ll temp = b;
b = a % b;
a = temp;
}
return a;
}
class compare{
public:
bool operator()(ll&a,ll&b){
return a<b;
}
};
class Node{
public:
int val;
char letter;
Node*left;
Node*right;
Node(int val,char letter){
this->letter=letter;
this->val=val;
left=NULL;
right=NULL;
}
};
ll bnsearch(ll low,ll high,vi &v,ll sum){
if(sum>v[high])return high;
while(low<high){
ll plus=(low+high)/2;
if(v[plus]>=sum)high=plus-1;
else low=plus+1;
}
if(v[low]>=sum)return -1;
else return low;
}
int main(){
#ifdef FELIX
auto _clock_start = chrono::high_resolution_clock::now();
#endif
ios::sync_with_stdio(false);
cin.tie(nullptr); cout.tie(nullptr);
#ifndef ONLINE_JUDGE
freopen("input.in", "r", stdin);
freopen("output.out", "w", stdout);
freopen("error.out", "w", stderr);
#endif
ll t;
cin>>t;
while(t--){
ll n;
cin>>n;
vector<pair<ll,ll>>v1;
vector<pair<ll,ll>>v2;
vector<ll>row1(n,0);
vector<ll>row2(n,0);
ip(row1,n);
ip(row2,n);
ll top=0;
ll down=0;
for(ll i=0;i<n;i++){
if(row1[i]>=row2[i]){v1.push_back({row1[i],row2[i]});top+=row1[i];}
else {v2.push_back({row1[i],row2[i]});down+=row2[i];}
}
ll ans=INT_MIN;
for(ll i=0;i<v1.size();i++){
ans=max(ans,top+v1[i].second+down);
}
for(ll i=0;i<v2.size();i++){
ans=max(ans,top+down+v2[i].first);
}
cout<<ans<<endl;
}
return 0;
}