text: // Time Complexity: O(n^2)
  // Space Complexity: O(n)
  
  class Solution {
      public:
          int minimumTotal(vector<vector<int> > &triangle) {
              const int N = triangle.size();
              vector<int> f(N, INT_MAX);
              int ans = INT_MAX;
  
              f[0] = triangle[0][0];
              for(int i = 1; i < N; ++i) {
                  for(int j = i; j > 0; --j) {
                      f[j] = min(f[j], f[j - 1]) + triangle[i][j];
                  }
                  f[0] += triangle[i][0];
              }
  
              for(int i = 0; i < N; ++i) {
                  ans = min(ans, f[i]);
              }
  
              return ans;
          }
  };
  