/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 320.0 KiB
#2 Accepted 1ms 324.0 KiB
#3 Accepted 1ms 324.0 KiB
#4 Accepted 2ms 580.0 KiB
#5 Accepted 31ms 624.0 KiB
#6 Accepted 38ms 6.941 MiB
#7 Accepted 38ms 6.949 MiB
#8 Accepted 38ms 7.035 MiB
#9 Accepted 34ms 6.879 MiB
#10 Accepted 34ms 6.816 MiB
#11 Accepted 34ms 6.969 MiB
#12 Accepted 34ms 6.949 MiB
#13 Accepted 34ms 6.812 MiB
#14 Accepted 34ms 6.863 MiB
#15 Accepted 35ms 6.949 MiB
#16 Accepted 35ms 6.957 MiB

Code

#include <bits/stdc++.h>

#pragma GCC optimize("Ofast")
using namespace std;

void solve(int cs) {
  int n;
  cin >> n;
  vector<int> a(n), b(n), c(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> b[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> c[i];
  }
  vector<vector<int64_t>> dp(n + 1, vector<int64_t>(3,0));
  for (int i = 0; i < n; i++) {
    dp[i + 1][0] = max(dp[i][1], dp[i][2]) + a[i];
    dp[i + 1][1] = max(dp[i][2], dp[i][0]) + b[i];
    dp[i + 1][2] = max(dp[i][1], dp[i][0]) + c[i];
  }
  cout << *max_element(dp.back().begin(), dp.back().end()) << "\n";
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int tc = 1;
  cin >> tc;
  for (int cs = 1; cs <= tc; cs++) {
    solve(cs);
  }
  return 0;
}

Information

Submit By
Type
Submission
Problem
P1046 Maximum sum in 3-array
Language
C++20 (G++ 13.2.0)
Submit At
2024-07-14 09:37:03
Judged At
2024-11-11 03:26:16
Judged By
Score
100
Total Time
38ms
Peak Memory
7.035 MiB