[InterviewBit] Tushar`s Birthday Party

Tushar’s Birthday Party

  • Time :
  • Space :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
int Solution::solve(const vector<int> &A, const vector<int> &B, const vector<int> &C) {
vector<long long> dp(1010, INT_MAX);
dp[0] = 0;
for(int i = 0; i < B.size(); i++) {
int cap = B[i], cost = C[i];
for(int j = cap; j < dp.size(); j++) {
dp[j] = min(dp[j], dp[j-cap] + cost);
}
}
int res = 0;
for(int i = 0; i < A.size(); i++) res += dp[A[i]];
return res;
}

Author: Song Hayoung
Link: https://songhayoung.github.io/2022/10/24/PS/interviewbit/tushars-birthday-party/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.