SHARE
TWEET

Untitled

Khody Feb 27th, 2020 71 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <fstream>
  3. #include <iomanip>
  4. #include <string>
  5. #include <vector>
  6. #include <algorithm>
  7. #include <cmath>
  8. #include <math.h>
  9. #include <set>
  10. #include <map>
  11. #include <queue>
  12. #include <deque>
  13. #include <stack>
  14.  
  15. #define pb push_back
  16. #define ff first
  17. #define ss second
  18. #define sqr(x) (x) * (x)
  19. #define cb(x) (x) * (x) * (x)
  20. #define SIZE 101
  21. #define INF 1e18 + 9
  22.  
  23. using namespace std;
  24.  
  25. typedef long long ll;
  26. typedef long double ld;
  27. typedef pair<int, int> pii;
  28. typedef pair<ll, ll> pll;
  29.  
  30. const int inf = 2e9;
  31. ll linf = 2e18;
  32.  
  33. template <typename T>
  34. ostream& operator << (ostream& s, vector<T>& v) {
  35.     for (auto el : v) {
  36.         s << el << " ";
  37.     }
  38.     return s;
  39. }
  40.  
  41.  
  42.  
  43. int main() {
  44. //3
  45.     ios_base::sync_with_stdio(0);
  46.     cin.tie(0), cout.tie(0);
  47.    
  48.     int n; cin >> n; n++;
  49.     vector<int> a(n), b(n), c(n);
  50.     for (int i = 1; i < n; i++)
  51.         cin >> a[i] >> b[i] >> c[i];
  52.  
  53.     vector<ll> dp(n);
  54.     dp[1] = a[1];
  55.  
  56.     for (int i = 2; i < n; i++) {
  57.         dp[i] = dp[i - 1] + a[i];
  58.         dp[i] = min(dp[i], dp[i - 2] + b[i - 1]);
  59.         if (i > 2) dp[i] = min(dp[i], dp[i - 3] + c[i - 2]);
  60.     }
  61.    
  62.     cout << dp[n - 1] << endl;
  63.     return 0;
  64. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top