/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 540.0 KiB
#2 Accepted 1ms 540.0 KiB
#3 Accepted 1ms 492.0 KiB
#4 Accepted 1ms 540.0 KiB
#5 Accepted 24ms 540.0 KiB
#6 Accepted 30ms 5.121 MiB
#7 Accepted 29ms 5.117 MiB
#8 Accepted 30ms 5.125 MiB
#9 Accepted 28ms 5.125 MiB
#10 Accepted 27ms 5.125 MiB
#11 Accepted 28ms 5.121 MiB
#12 Accepted 28ms 5.121 MiB
#13 Accepted 28ms 5.059 MiB
#14 Accepted 28ms 5.125 MiB
#15 Accepted 28ms 5.047 MiB
#16 Accepted 28ms 4.98 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-03-27 16:43:26
Judged By
Score
100
Total Time
30ms
Peak Memory
5.125 MiB