Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //hey bhagwan AC kara de :''}
- #include<bits/stdc++.h>
- using namespace std;
- #define fo(i,n) for (int i = 0; i < n; ++i)
- #define tr(i,n) for(auto i=n.begin();i!=n.end();i++)
- #define w(t) while(t--)
- #define ll long long int
- #define pb push_back
- #define mp make_pair
- #define f first
- #define s second
- #define fst ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
- #define all(x) (x).begin(), (x).end()
- const ll mod = 1000000007;
- int a[100001];
- int b[100001];
- int c[100001];
- int find(int n, int curr, int id)
- {
- if (n == 0)
- {
- if (id == 0) {
- int ans = curr + max(b[0], c[0]);
- return ans;
- }
- if (id == 1) {
- int ans = curr + max(a[0], c[0]);
- return ans;
- }
- if (id == 2) {
- int ans = curr + max(a[0], b[0]);
- return ans;
- }
- }
- if (id == 0) {
- return max(find(n - 1, curr + b[n], 1), find(n - 1, curr + c[n], 2));
- }
- else if (id == 1) {
- return max(find(n - 1, curr + a[n], 0), find(n - 1, curr + c[n], 2));
- }
- else {
- return max(find(n - 1, curr + a[n], 0), find(n - 1, curr + b[n], 1));
- }
- }
- void solve()
- {
- int n;
- cin >> n;
- fo(i, n)
- cin >> a[i] >> b[i] >> c[i];
- int a1 = find(n - 1, 0, 0);
- int a2 = find(n - 1, 0, 1);
- int a3 = find(n - 1, 0, 2);
- cout << max({a1, a2, a3});
- }
- int main()
- {
- fst;
- solve();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement