Advertisement
Guest User

Untitled

a guest
Dec 30th, 2020
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.46 KB | None | 0 0
  1. //hey bhagwan AC kara de :''}
  2. #include<bits/stdc++.h>
  3. using namespace std;
  4.  
  5. #define fo(i,n) for (int i = 0; i < n; ++i)
  6. #define tr(i,n) for(auto i=n.begin();i!=n.end();i++)
  7. #define w(t) while(t--)
  8. #define ll long long int
  9. #define pb push_back
  10. #define mp make_pair
  11. #define f first
  12. #define s second
  13. #define fst ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
  14. #define all(x) (x).begin(), (x).end()
  15. const ll mod = 1000000007;
  16. int a[100001];
  17. int b[100001];
  18. int c[100001];
  19. int find(int n, int curr, int id)
  20. {
  21.    
  22.     if (n == 0)
  23.     {
  24.  
  25.         if (id == 0) {
  26.             int ans = curr + max(b[0], c[0]);
  27.             return ans;
  28.         }
  29.         if (id == 1) {
  30.             int ans = curr + max(a[0], c[0]);
  31.             return ans;
  32.         }
  33.         if (id == 2) {
  34.             int ans = curr + max(a[0], b[0]);
  35.             return ans;
  36.         }
  37.     }
  38.     if (id == 0) {
  39.         return max(find(n - 1, curr + b[n], 1), find(n - 1, curr + c[n], 2));
  40.     }
  41.     else if (id == 1) {
  42.         return max(find(n - 1, curr + a[n], 0), find(n - 1, curr + c[n], 2));
  43.     }
  44.     else {
  45.         return max(find(n - 1, curr + a[n], 0), find(n - 1, curr + b[n], 1));
  46.     }
  47.  
  48. }
  49.  
  50. void solve()
  51. {
  52.     int n;
  53.     cin >> n;
  54.     fo(i, n)
  55.     cin >> a[i] >> b[i] >> c[i];
  56.  
  57.     int a1 = find(n - 1, 0, 0);
  58.     int a2 = find(n - 1, 0, 1);
  59.     int a3 = find(n - 1, 0, 2);
  60.     cout << max({a1, a2, a3});
  61. }
  62.  
  63. int main()
  64. {
  65.     fst;
  66.     solve();
  67. }
  68.  
  69.  
  70.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement