/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 328.0 KiB
#2 Accepted 2ms 332.0 KiB
#3 Accepted 2ms 512.0 KiB
#4 Accepted 2ms 540.0 KiB
#5 Accepted 44ms 608.0 KiB
#6 Accepted 53ms 5.031 MiB
#7 Accepted 54ms 5.129 MiB
#8 Accepted 53ms 4.965 MiB
#9 Accepted 48ms 4.996 MiB
#10 Accepted 49ms 5.129 MiB
#11 Accepted 49ms 5.133 MiB
#12 Accepted 48ms 5.129 MiB
#13 Accepted 49ms 5.125 MiB
#14 Accepted 49ms 5.133 MiB
#15 Accepted 48ms 4.977 MiB
#16 Accepted 49ms 5.133 MiB

Code

/**
 *  written by Binoy Barman .
**/

#include<bits/stdc++.h>
using namespace std;
#define nl '\n'
#define all(v) v.begin(), v.end()
#define Too_Many_Jobs int tts, tc = 1; cin >> tts; hell: while(tts--)
#define Dark_Lord_Binoy ios_base::sync_with_stdio(false); cin.tie(NULL);

#ifdef LOCAL
#include "unravel.hpp"
#else
#define dbg(...) 42
#endif
#define ll long long

int32_t main() {
Dark_Lord_Binoy
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    Too_Many_Jobs {
        ll n;
        cin >> n;
        ll a[3][n], dp[3][n];
        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < n; j++) {
                cin >> a[i][j];
            }
        }
        dp[0][0] = a[0][0], dp[1][0] = a[1][0], dp[2][0] = a[2][0];
        for (int i = 1; i < n; i++) {
            dp[0][i] = max(dp[1][i - 1], dp[2][i - 1]) + a[0][i];
            dp[1][i] = max(dp[0][i - 1], dp[2][i - 1]) + a[1][i];
            dp[2][i] = max(dp[0][i - 1], dp[1][i - 1]) + a[2][i];
        }
        cout << max({dp[0][n - 1], dp[1][n - 1], dp[2][n - 1]}) << nl;
    }

    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 16:43:26
Judged At
2024-11-11 03:38:13
Judged By
Score
100
Total Time
54ms
Peak Memory
5.133 MiB