Untitled

mail@pastecode.io avatar
unknown
c_cpp
3 years ago
991 B
0
Indexable
Never
#include <iostream>
using namespace std;
const int maxn = 100005;
int n;
int niza[maxn][3];
int memo[maxn][4];
int main()
{
    cin >> n;
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < 3; j++) {
            cin >> niza[i][j];
            memo[i][j] = -2e9;
        }
    }
    memo[0][0] = niza[0][0];
    memo[0][1] = niza[0][1];
    memo[0][2] = niza[0][2];
    for(int i = 1; i < n; i++) {
        for(int prev_activity = 0; prev_activity < 3; prev_activity++) {
            for(int next_activity = 0; next_activity < 3; next_activity++) {
                if(prev_activity != next_activity) {
                    memo[i][next_activity] = max(memo[i][next_activity], memo[i - 1][prev_activity] + niza[i][next_activity]);
                }
            }
        }
    }
    int najgolem = 0;
    najgolem = max(najgolem, memo[n - 1][0]);
    najgolem = max(najgolem, memo[n - 1][1]);
    najgolem = max(najgolem, memo[n - 1][2]);
    cout << najgolem << endl;
    return 0;
}