Submission #13759349


Source Code Expand

Copy
#include <bits/stdc++.h>
 
 
#define FAST_IO ios_base::sync_with_stdio(false), cin.tie(nullptr)
using namespace std;
 
signed main() {
    FAST_IO;
 
    int n;
    cin >> n;
    int a[n], b[n], c[n];
    for (int i = 0; i < n; i++) cin >> a[i] >> b[i] >> c[i];

    int dp[n][3]; // dp[i][j] : i represents the day and j represents the activity
    				         // j is 0 for activity A, 1 for activity B and 2 for activity C

  	// Set the base values
    dp[0][0] = a[0]; // If you swim in the sea in sea on the first day, you cannot get more than a[0] points.
    dp[0][1] = b[0]; // If you catch bugs in the mountains on the first day, you cannot get more than b[0] points.
    dp[0][2] = c[0]; // If you do homework at home on the first day, you cannot get more than c[0] points.

    // i represents what day it is (0 based indexing)
    for (int i = 1; i < n; i++) { 
        dp[i][0] = a[i] + max(dp[i - 1][1], dp[i - 1][2]); // If we do activity A today, we have to have done activities B or C on the previous day.
        dp[i][1] = b[i] + max(dp[i - 1][0], dp[i - 1][2]); // If we do activity B today, we have to have done activities A or C on the previous day.
        dp[i][2] = c[i] + max(dp[i - 1][1], dp[i - 1][0]); // If we do activity C today, we have to have done activities A or B on the previous day.
    }

  	// Our answer is the maximum of all the points gained by doing activity A, B, or C on the last day.
    cout << max({dp[n - 1][0], dp[n - 1][1], dp[n - 1][2]}); 
    return 0;
}

Submission Info

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

Judge Result

Set Name All
Score / Max Score 100 / 100
Status
AC × 13
Set Name Test Cases
All 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 AC 1 ms 256 KB
0_01 AC 1 ms 256 KB
0_02 AC 1 ms 256 KB
1_00 AC 1 ms 256 KB
1_01 AC 25 ms 2560 KB
1_02 AC 24 ms 2560 KB
1_03 AC 24 ms 2560 KB
1_04 AC 24 ms 2560 KB
1_05 AC 24 ms 2560 KB
1_06 AC 24 ms 2560 KB
1_07 AC 24 ms 2560 KB
1_08 AC 24 ms 2560 KB
1_09 AC 24 ms 2560 KB