There is a matrix consisting of 2 rows and π columns. The rows are numbered from 1 to 2β¦
- User
There is a matrix consisting of 2 rows and π columns. The rows are numbered from 1 to 2 from top to bottom; the columns are numbered from 1 to π from left to right. Let's denote the cell on the intersection of the π-th row and the π-th column as (π,π). Each cell contains an integer; initially, the integer in the cell (π,π) is ππ,π.
You can perform the following operation any number of times (possibly zero):
choose two columns and swap them (i.βe. choose two integers π₯ and π¦ such that 1β€π₯<π¦β€π, then swap π1,π₯ with π1,π¦, and then swap π2,π₯ with π2,π¦). After performing the operations, you have to choose a path from the cell (1,1) to the cell (2,π). For every cell (π,π) in the path except for the last, the next cell should be either (π+1,π) or (π,π+1). Obviously, the path cannot go outside the matrix.
The cost of the path is the sum of all integers in all (π+1) cells belonging to the path. You have to perform the operations and choose a path so that its cost is maximum possible.
Input Each test contains multiple test cases. The first line contains the number of test cases π‘ (1β€π‘β€5000). The description of the test cases follows.
Each test case consists of three lines:
the first line contains one integer π (1β€πβ€5000) β the number of columns in the matrix; the second line contains π integers π1,1,π1,2,β¦,π1,π (β105β€ππ,πβ€105) β the first row of the matrix; the third line contains π integers π2,1,π2,2,β¦,π2,π (β105β€ππ,πβ€105) β the second row of the matrix. It is guaranteed that the sum of π over all test cases does not exceed 5000.
Output For each test case, print one integer β the maximum cost of a path you can obtain.
Example inputCopy 3 1 -10 5 3 1 2 3 10 -5 -3 4 2 8 5 3 1 10 3 4 outputCopy -5 16 29 Note Here are the explanations of the first three test cases of the example. The left matrix is the matrix given in the input, the right one is the state of the matrix after several column swaps (possibly zero). The optimal path is highlighted in green. #include #include #include
using namespace std;
// const int N = 2e5 + 5; // int a[N]; typedef long long ll; typedef vector vi; #define endl '\n'
void solve() { //your code here
}
int main(){ ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t; cin >> t; while(t--) solve(); }
- Assistant