classSolution { public: doublecalculateTax(vector<vector<int>>& nums, int sum){ double ans = 0.0; int prev = 0; for (auto& num : nums) { int cur = min(num[0] - prev, sum); ans += cur * num[1] * 0.01; prev = num[0]; sum -= cur; } return ans; } };
classSolution { public: intminPathCost(vector<vector<int>>& nums, vector<vector<int>>& cost){ int n = nums.size(), m = nums[0].size(); vector<vector<int>> f(n, vector<int>(m, 1e9)); for (int i = 0; i < n - 1; i ++ ) for (int j = 0; j < m; j ++ ) { if (i == 0) f[i][j] = nums[i][j]; for (int k = 0; k < m; k ++ ) f[i + 1][k] = min(f[i + 1][k], f[i][j] + nums[i + 1][k] + cost[nums[i][j]][k]); } return *min_element(f[n - 1].begin(), f[n - 1].end()); } };