/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 540.0 KiB
#2 Accepted 1ms 508.0 KiB
#3 Accepted 1ms 540.0 KiB
#4 Accepted 1ms 548.0 KiB
#5 Accepted 25ms 540.0 KiB
#6 Accepted 29ms 3.223 MiB
#7 Accepted 29ms 3.227 MiB
#8 Accepted 30ms 3.219 MiB
#9 Accepted 27ms 3.145 MiB
#10 Accepted 27ms 3.223 MiB
#11 Accepted 27ms 3.145 MiB
#12 Accepted 27ms 3.145 MiB
#13 Accepted 27ms 3.145 MiB
#14 Accepted 27ms 3.145 MiB
#15 Accepted 27ms 3.02 MiB
#16 Accepted 27ms 3.145 MiB

Code

#include<bits/stdc++.h>
using namespace std;
const long long M=2e5+10,MOD=2000000007;
typedef long long ll;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t=1;
    cin>>t;
    while(t--){
    int n;
    cin>>n;
    vector<vector<int>>dp(4,vector<int>(n+2,-1e9));
    dp[1][0]=dp[2][0]=dp[3][0]=0;
    vector<int>a(n+1),b(n+1),c(n+1);
    for(int i=1;i<=n;i++)cin>>a[i];
    for(int i=1;i<=n;i++)cin>>b[i];
    for(int i=1;i<=n;i++)cin>>c[i];
    for(int i=1;i<=n;i++){
         dp[1][i]=max(dp[2][i-1],dp[3][i-1])+a[i];
         dp[2][i]=max(dp[1][i-1],dp[3][i-1])+b[i];
         dp[3][i]=max(dp[1][i-1],dp[2][i-1])+c[i];
    }
    cout<<max({dp[1][n],dp[2][n],dp[3][n]})<<"\n";


    
   }
   return 0;
 
}

Information

Submit By
Type
Submission
Problem
P1046 Maximum sum in 3-array
Language
C++20 (G++ 13.2.0)
Submit At
2024-03-26 13:23:36
Judged At
2024-03-26 13:23:36
Judged By
Score
100
Total Time
30ms
Peak Memory
3.227 MiB