Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public:
- int minRefuelStops(int target, int startFuel, vector<vector<int>>& stations) {
- int len = stations.size();
- vector<long> dp(len + 1, 0);
- dp[0] = startFuel;
- for (int i = 0; i < len; ++i)
- {
- for (int j = i + 1; j > 0; --j)
- {
- if (dp[j - 1] >= stations[i][0])
- dp[j] = max(dp[j], dp[j - 1] + static_cast<long>(stations[i][1]));
- }
- }
- for (int i = 0; i <= len; ++i)
- if (dp[i] >= target)return i;
- return -1;
- }
- };
Add Comment
Please, Sign In to add comment