forked from doocs/leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSolution.cpp
37 lines (33 loc) · 826 Bytes
/
Solution.cpp
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
30
31
32
33
34
35
36
37
class ATM {
public:
ATM() {
}
void deposit(vector<int> banknotesCount) {
for (int i = 0; i < banknotesCount.size(); ++i) {
cnt[i] += banknotesCount[i];
}
}
vector<int> withdraw(int amount) {
vector<int> ans(5);
for (int i = 4; ~i; --i) {
ans[i] = min(1ll * amount / d[i], cnt[i]);
amount -= ans[i] * d[i];
}
if (amount > 0) {
return {-1};
}
for (int i = 0; i < 5; ++i) {
cnt[i] -= ans[i];
}
return ans;
}
private:
long long cnt[5] = {0};
int d[5] = {20, 50, 100, 200, 500};
};
/**
* Your ATM object will be instantiated and called as such:
* ATM* obj = new ATM();
* obj->deposit(banknotesCount);
* vector<int> param_2 = obj->withdraw(amount);
*/