-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path638.cpp
More file actions
29 lines (29 loc) · 938 Bytes
/
Copy path638.cpp
File metadata and controls
29 lines (29 loc) · 938 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
class Solution {
public:
int shoppingOffers(vector<int> &price, vector<vector<int>> &special, vector<int> &needs) {
int base = 0, size = needs.size();
bool empty = true;
for (int i = 0; i < size; ++i) {
if (needs[i] != 0)
empty = false;
base += price[i] * needs[i];
}
if (empty)
return 0;
for (int i = 0; i < special.size(); ++i) {
vector<int> temp;
int remain = 0;
for (int j = 0; j < size; ++j) {
if (j == special[i].size() - 1)
break;
remain = needs[j] - special[i][j];
if (remain < 0)
break;
temp.push_back(remain);
}
if (remain >= 0)
base = min(base, shoppingOffers(price, special, temp) + special[i][size]);
}
return base;
}
};