/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 764.0 KiB
#2 Accepted 2ms 576.0 KiB
#3 Accepted 45ms 652.0 KiB
#4 Accepted 30ms 628.0 KiB
#5 Accepted 41ms 620.0 KiB
#6 Accepted 48ms 712.0 KiB
#7 Accepted 54ms 644.0 KiB
#8 Accepted 51ms 1.488 MiB
#9 Accepted 36ms 1.504 MiB

Code

// BISMILLAH

#include "bits/stdc++.h"

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

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

void init(int N) {
	for (int i = 0; i < 2; i++) {
		for (int j = 0; j < N; j++) {
			dp[i][j] = dp1[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] = b[i][j] = x;
				if (j > 0 && j+1 < N)
					b[i][j] = -j - 1;
			}
		}
		init(N);
		dp[0][0] = dp1[0][0] = a[0][0];
		for (int j = 1; j < N; j++) {
			dp[0][j] = dp[0][j - 1] + std::max(a[0][j], b[0][j]);
		}
		for (int j = 1; j < N; j++) {
			dp1[0][j] = dp[0][j - 1] + a[0][j];
		}
		dp[1][N-1] = dp1[1][N-1] = a[1][N-1];
		for (int j = N-2; j >= 0; j--) {
			dp[1][j] = dp[1][j + 1] + std::max(a[1][j], b[1][j]);
		}
		for (int j = N-2; j >= 0; j--) {
			dp1[1][j] = dp[1][j + 1] + a[1][j];
		}
		ll ans = LLONG_MIN;
		for (int j = 0; j < N; j++) {
			ans = std::max(ans, dp1[0][j] + dp1[1][j]);
		}
		printf("%lld\n", ans);
		// for (int i = 0;i < 2; i++) {
		// 	for (int j = 0; j < N; j++) {
		// 		printf("%lld ", dp1[i][j]);
		// 	}
		// 	printf("\n");
		// }
	}
	
	return 0;
}

/*

*/

Information

Submit By
Type
Submission
Problem
P1050 Game on 2d grid
Language
C++17 (G++ 13.2.0)
Submit At
2024-05-08 12:25:20
Judged At
2024-11-11 03:30:24
Judged By
Score
100
Total Time
54ms
Peak Memory
1.504 MiB