-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathC.cpp
More file actions
129 lines (104 loc) · 3.18 KB
/
C.cpp
File metadata and controls
129 lines (104 loc) · 3.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
// Jai Mata Di..
//
// @ author : Sanjit Anand (sanjit_15)
//
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template<typename T>
using order_set = tree<T, null_type, less<T>, rb_tree_tag , tree_order_statistics_node_update>;
template<typename T>
using order_multiset = tree<T,null_type,less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define int long long
#define PI 3.1415926535897932384626
#define gc getchar_unlocked
#define fo(i,n) for(i=0;i<n;i++)
#define rep(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define pf pop_front
#define ppb pop_back
#define ppf pop_front
#define F first
#define S second
#define trav(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define ppc __builtin_popcount
#define ppcll __builtin_popcountll
#define ctzll __builtin_ctzll
#define clzll __builtin_clzll
#define all(x) x.begin(),x.end()
template<typename T1,typename T2>istream& operator>>(istream& in,pair<T1,T2> &a){in>>a.fr>>a.sc;return in;}
template<typename T1,typename T2>ostream& operator<<(ostream& out,pair<T1,T2> a){out<<a.fr<<" "<<a.sc;return out;}
template<typename T,typename T1>T amax(T &a,T1 b){if(b>a)a=b;return a;}
template<typename T,typename T1>T amin(T &a,T1 b){if(b<a)a=b;return a;}
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef vector<vi> vvi;
typedef set<int> si;
typedef list<int> li;
typedef tuple<int> tpi;
const long long INF = 1e18;
const long long MOD = 1000000007;
const long long MM = 998244353;
const int N = 2000010;
int mpow(int base, int exp, int m);
int gcd(int a, int b);
int ar[100005][4];
int dp[100005][4];
int helper(int n){
dp[1][1] = ar[1][1];
dp[1][2] = ar[1][2];
dp[1][3] = ar[1][3];
for(int i=2; i<=n; i++){
dp[i][1] = ar[i][1] + max(dp[i-1][2], dp[i-1][3]);
dp[i][2] = ar[i][2] + max(dp[i-1][1], dp[i-1][3]);
dp[i][3] = ar[i][3] + max(dp[i-1][1], dp[i-1][2]);
}
return max({dp[n][1], dp[n][2], dp[n][3]});
}
void solve() {
int i, j, n, k;
cin >> n;
for(int i=1; i<=n; i++){
for(int j=1; j<=3; j++){
cin >> ar[i][j];
}
}
memset(dp, -1, sizeof(dp));
cout << helper(n);
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
#ifdef NCR
pmain();
#endif
#ifdef SIEVE
sieve();
#endif
int t = 1;
// cin >> t;
while(t--) {
solve();
}
return 0;
}
int gcd(int a, int b){
return b==0 ? a : gcd(b,a%b);
}
int mpow(int base, int exp, int m=MOD) {
base %= m;
int result = 1;
while (exp > 0) {
if (exp & 1) result = ((long long)result * base) % m;
base = ((long long)base * base) % m;
exp >>= 1;
}
return result;
}