/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 2.527 MiB
#2 Accepted 2ms 2.578 MiB
#3 Accepted 2ms 2.527 MiB
#4 Accepted 2ms 2.562 MiB
#5 Accepted 25ms 2.527 MiB
#6 Accepted 29ms 5.07 MiB
#7 Accepted 28ms 5.125 MiB
#8 Accepted 28ms 4.996 MiB
#9 Accepted 26ms 5.078 MiB
#10 Accepted 26ms 5.109 MiB
#11 Accepted 26ms 4.895 MiB
#12 Accepted 27ms 5.039 MiB
#13 Accepted 26ms 5.047 MiB
#14 Accepted 27ms 5.121 MiB
#15 Accepted 26ms 5.078 MiB
#16 Accepted 26ms 4.996 MiB

Code

#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N = 1e5 + 10;
const int p = 1e6 + 7;
int a[N] , b[N] , c[N] , dp1[N] , dp2[N] , dp3[N];
signed main()
{
    // #ifndef ONLINE_JUDGE
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    // #endif

    ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);
    int T; cin>>T;
    while (T--)
    {
        int n;cin >> n;
        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++)
        {
            dp1[i] = max(dp2[i - 1] , dp3[i - 1]) + a[i];
            dp2[i] = max(dp1[i - 1] , dp3[i - 1]) + b[i];
            dp3[i] = max(dp1[i - 1] , dp2[i - 1]) + c[i];
        }
        cout << max(max(dp1[n] , dp2[n]) , dp3[n])<<endl;
    }
    
    return 0;
}

Information

Submit By
Type
Submission
Problem
P1046 Maximum sum in 3-array
Contest
TLE_Headquarters - round #1
Language
C++20 (G++ 13.2.0)
Submit At
2024-03-27 17:03:27
Judged At
2024-03-27 17:03:27
Judged By
Score
100
Total Time
29ms
Peak Memory
5.125 MiB