/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 324.0 KiB
#2 Accepted 1ms 320.0 KiB
#3 Accepted 157ms 604.0 KiB
#4 Accepted 129ms 620.0 KiB
#5 Accepted 114ms 588.0 KiB
#6 Accepted 153ms 644.0 KiB
#7 Accepted 174ms 568.0 KiB
#8 Accepted 169ms 1.066 MiB
#9 Accepted 72ms 1.133 MiB

Code

#include<bits/stdc++.h>
#define ll long long 
using namespace std;

int main(){
  int t;
  cin >> t;
  while (t--){
    int n;
    cin >> n;
    ll a[2][n + 1], dp[2][n + 1];
    for (int i = 0; i < 2; i++){
      for (int j = 1; j <= n; j++){
        cin >> a[i][j];
        dp[i][j] = 0;
      }
    }
    dp[0][1] = a[0][1];
    dp[1][1] = a[0][1] + a[1][1];
    for (int i = 2; i < n; i++){
      dp[0][i] = dp[0][i - 1] + max(a[0][i], 1LL * (-i));
      dp[1][i] = max(dp[0][i - 1] + a[0][i] + a[1][i], dp[1][i - 1] + max(a[1][i], 1LL * (-i)));
    }
    if (n > 1) cout << max(dp[0][n - 1] + a[0][n], dp[1][n - 1]) + a[1][n] << endl;
    else cout << dp[1][1] << endl;
  }
}

Information

Submit By
Type
Submission
Problem
P1050 Game on 2d grid
Contest
Brain Booster #3
Language
C++17 (G++ 13.2.0)
Submit At
2024-05-06 17:17:03
Judged At
2024-11-11 03:32:21
Judged By
Score
100
Total Time
174ms
Peak Memory
1.133 MiB