#include <algorithm> #include <iostream> #include <cstring> #include <iomanip> #include <cstdlib> #include <climits> #include <cstdio> #include <bitset> #include <string> #include <vector> #include <cctype> #include <stack> #include <queue> #include <deque> #include <cmath> #include <map> #include <set>
#define I inline #define fi first #define se second #define pb push_back #define MP make_pair #define PII pair<int , int> #define PSL pair<string , long long> #define PLL pair<long long , long long> #define all(x) (x).begin() , (x).end() #define copy(a , b) memcpy(a , b , sizeof(b)) #define clean(a , b) memset(a , b , sizeof(a)) #define rep(i , l , r) for (int i = (l); i <= (r); i ++) #define per(i , r , l) for (int i = (r); i >= (l); i --) #define PE(i , x) for(int i = head[x]; i; i = edge[i].last) #define DEBUG(x) std :: cerr << #x << '=' << x << std :: endl
typedef long long ll; typedef unsigned long long ull;
template <class T> inline void read(T &x) { char c = getchar(), f = 0; x = 0; while (!isdigit(c)) f = (c == '-'), c = getchar(); while (isdigit(c)) x = x * 10 + c - '0', c = getchar(); x = f ? -x : x; }
using namespace std;
const int N = 10001; const int M = 100001; const int HA = 998244353;
int n , a[M] , b[M] , f[30][30][30][30];
int dfs(int al , int ar , int bl , int br , int sm){ if(f[al][ar][bl][br]) return f[al][ar][bl][br]; if(al > ar && bl > br) return 0; int ans = 0; if(al <= ar){ ans = max(ans , sm - dfs(al + 1 , ar , bl , br , sm - a[al])); ans = max(ans , sm - dfs(al , ar - 1 , bl , br , sm - a[ar])); } if(bl <= br){ ans = max(ans , sm - dfs(al , ar , bl + 1 , br , sm - b[bl])); ans = max(ans , sm - dfs(al , ar , bl , br - 1 , sm - b[br])); } f[al][ar][bl][br] = ans; return ans; }
void solve(){ read(n); ll sm = 0; rep(i , 1 , n) read(a[i]) , sm += a[i]; rep(i , 1 , n) read(b[i]) , sm += b[i]; clean(f , 0); ll res = dfs(1 , n , 1 , n , sm); printf("%d\n" , res); }
int main() { #ifdef LOCAL freopen("try.in" , "r" , stdin); freopen("try1.out" , "w" , stdout); #endif int t; read(t); while(t --) solve();
return 0; }
|