Submission #3938380


Source Code Expand

Copy
/**
 *    author:  border
 *    created: 06.01.2019 17:22:09     
**/
#include <bits/stdc++.h>

using namespace std;

#define debug(s) cout<< #s <<" = "<< s <<endl
#define all(v) (v).begin(), (v).end()
#define mem(a,val) memset(a,val,sizeof a)

#define ll long long
#define ff first
#define ss second
#define pb push_back
#define endl '\n'

int a[100010][3],dp[100010][3];

int main()
{
  ios_base::sync_with_stdio(false);cin.tie(NULL);
  /*#ifndef ONLINE_JUDGE
    freopen("in", "r", stdin);
    freopen("out","w",stdout);
  #endif*/
  int n;
  cin >> n;
  for(int i = 0; i < n; ++i){
    cin >> a[i][0] >> a[i][1] >> a[i][2];
  }
  dp[n-1][0] = a[n-1][0];
  dp[n-1][1] = a[n-1][1];
  dp[n-1][2] = a[n-1][2];
  for(int i = n-2; i >= 0; --i){
    dp[i][0] = max(dp[i+1][1],dp[i+1][2])+a[i][0];
    dp[i][1] = max(dp[i+1][0],dp[i+1][2])+a[i][1];
    dp[i][2] = max(dp[i+1][0],dp[i+1][1])+a[i][2];
  }
  cout << max(dp[0][0],max(dp[0][1],dp[0][2])) << endl;
}


Submission Info

Submission Time
Task C - Vacation
User border
Language C++14 (GCC 5.4.1)
Score 100
Code Size 1004 Byte
Status
Exec Time 25 ms
Memory 2560 KB

Test Cases

Set Name Score / Max Score Test Cases
All 100 / 100 0_00, 0_01, 0_02, 1_00, 1_01, 1_02, 1_03, 1_04, 1_05, 1_06, 1_07, 1_08, 1_09
Case Name Status Exec Time Memory
0_00 1 ms 256 KB
0_01 1 ms 256 KB
0_02 1 ms 256 KB
1_00 1 ms 256 KB
1_01 25 ms 2560 KB
1_02 24 ms 2560 KB
1_03 24 ms 2560 KB
1_04 24 ms 2560 KB
1_05 23 ms 2560 KB
1_06 24 ms 2560 KB
1_07 23 ms 2560 KB
1_08 23 ms 2560 KB
1_09 23 ms 2560 KB