fork download
  1. /*
  2. * Author: Geeza
  3. */
  4.  
  5. #include <bits/stdc++.h>
  6.  
  7. #define ld long double
  8. #define ll long long
  9. #define pb push_back
  10. #define fin(a, n) for(int i = a; i < n; i++)
  11. #define fjn(a, n) for(int j = a; j < n; j++)
  12. #define all(a) a.begin(),a.end()
  13. #define allr(a) a.rbegin(),a.rend()
  14. #define FAST ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
  15.  
  16. using namespace std;
  17.  
  18. const double PI = acos(-1);
  19. const int N = 1e5+20;
  20. const ll oo = 0x3f3f3f3f3f3f3f3f;
  21. const int MOD = 1000000007, inf = 1e6;
  22.  
  23. string di[] = {"D","L", "U", "R", "UL", "UR", "DL", "DR"};
  24. int dx[] = {+1, +0, +0, -1, -1, -1, +1, +1};
  25. int dy[] = {+0, -1, +1, +0, -1, +1, -1, +1};
  26. char dc[] = {'D', 'L', 'R', 'U'};
  27.  
  28. void solve() {
  29. int n; cin >> n;
  30. vector<array<ll, 3>> v(n, {0, 0, 0});
  31.  
  32. fin(0, n) cin >> v[i][0] >> v[i][1] >> v[i][2];
  33. vector<array<ll, 3>> dp(n, {-oo, -oo, -oo});
  34.  
  35. dp[0][0] = v[0][0];
  36. dp[0][1] = v[0][1];
  37. dp[0][2] = v[0][2];
  38.  
  39. fin(1, n) {
  40. dp[i][0] = max({dp[i][0], dp[i-1][1]+v[i][0], dp[i-1][2]+v[i][0]});
  41. dp[i][1] = max({dp[i][1], dp[i-1][0]+v[i][1], dp[i-1][2]+v[i][1]});
  42. dp[i][2] = max({dp[i][2], dp[i-1][0]+v[i][2], dp[i-1][1]+v[i][2]});
  43. }
  44.  
  45. cout << max({dp[n-1][0], dp[n-1][1], dp[n-1][2]}) << "\n";
  46. }
  47.  
  48. int main() {
  49. FAST;
  50. #ifndef ONLINE_JUDGE
  51. freopen("input.txt","r",stdin);
  52. freopen("output.txt","w",stdout);
  53. #endif
  54. int tt = 1; //cin >> tt;
  55. while(tt--){
  56. solve();
  57. }
  58. return 0;
  59. }
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
0