/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 2.57 MiB
#2 Accepted 3ms 2.574 MiB
#3 Accepted 3ms 2.504 MiB
#4 Accepted 3ms 2.57 MiB
#5 Accepted 44ms 2.562 MiB
#6 Accepted 50ms 5.102 MiB
#7 Accepted 49ms 4.934 MiB
#8 Accepted 50ms 5.031 MiB
#9 Accepted 43ms 5.109 MiB
#10 Accepted 42ms 4.949 MiB
#11 Accepted 47ms 5.09 MiB
#12 Accepted 45ms 4.957 MiB
#13 Accepted 45ms 5.062 MiB
#14 Accepted 46ms 5.094 MiB
#15 Accepted 46ms 5.125 MiB
#16 Accepted 46ms 4.891 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-11-11 03:37:48
Judged By
Score
100
Total Time
50ms
Peak Memory
5.125 MiB