/ SeriousOJ /

Record Detail

Accepted


  

Code

// BISMILLAH

#include "bits/stdc++.h"

#define ll long long int
const int mxN = 500005, inf = 1000000005;

int N, a[2][mxN];
ll dp[2][mxN];

void init(int N) {
	for (int i = 0; i < 2; i++) {
		for (int j = 0; j < N; j++) {
			dp[i][j] = 0;
		}
	}
}

signed main() {
	int testCases=1;
	scanf("%lld",&testCases);
	// std::cin >> testCases;
	
	for (int T = 1; T <= testCases; T++) {
		scanf("%d", &N);
		for (int i = 0; i < 2; i++) {
			for (int j = 0,x; j < N; j++) {
				scanf("%d", &x);
				a[i][j] = x;
				if (j > 0 && j+1 < N) a[i][j] = std::max(x, -j - 1);
			}
		}
		init(N);
		dp[0][0] = a[0][0];
		for (int j = 1; j < N; j++) {
			dp[0][j] = dp[0][j - 1] + a[0][j];
		}
		dp[1][0] = dp[0][0] + a[1][0];
		for (int j = 1; j < N; j++) {
			dp[1][j] = std::max(dp[0][j], dp[1][j - 1]) + a[1][j];
		}
		printf("%lld\n", dp[1][N - 1]);
		// for (int i = 0;i < 2; i++) {
		// 	for (int j = 0; j < N; j++) {
		// 		printf("%lld ", dp[i][j]);
		// 	}
		// 	printf("\n");
		// }
	}
	
	return 0;
}

/*

*/

Information

Submit By
Type
Pretest
Problem
P1050 Game on 2d grid
Language
C++17 (G++ 13.2.0)
Submit At
2024-05-08 05:43:31
Judged At
2024-11-11 03:30:46
Judged By
Score
0
Total Time
0ms
Peak Memory
0 Bytes