-
Notifications
You must be signed in to change notification settings - Fork 4
/
bancomat.cpp
48 lines (42 loc) · 1009 Bytes
/
bancomat.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
38
39
40
41
42
43
44
45
46
47
48
#include <fstream>
#include <vector>
using namespace std;
const vector<unsigned> val{1,5,10,50,100,500};
vector<unsigned long long> cnt(6,0);
bool canBeGiven(unsigned long long s) {
vector<unsigned long long> tmp = cnt;
for(int bI = 5; bI >= 0 && s != 0; bI--) {
unsigned nB = s/val[bI];
if(nB <= cnt[bI]) {
cnt[bI] -= nB;
s-=nB*val[bI];
}
else {
s-=cnt[bI]*val[bI];
cnt[bI] = 0;
}
}
if(s==0)
return true;
cnt = tmp;
return false;
}
int main() {
ifstream in("bancomat.in");
size_t t;
in >> t;
ofstream out("bancomat.out");
while(t--) {
for(size_t i = 0; i < 6; ++i)
in >> cnt[i];
size_t n;
in >> n;
bool canGiveAll = true;
while(n--) {
unsigned long long s;
in >> s;
canGiveAll = canGiveAll && canBeGiven(s);
}
out << (canGiveAll?"YES":"NO") << '\n';
}
}