-
Notifications
You must be signed in to change notification settings - Fork 2
/
1069.cpp
38 lines (33 loc) · 898 Bytes
/
1069.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
#include <cstdio>
#include <cstring>
#define MAX_N 105
#define MAX_M 100005
using namespace std;
int n, m;
int w[MAX_N], c[MAX_N], sum[MAX_M], f[MAX_M];
int main() {
while (~scanf("%d%d", &n, &m)) {
if (n == 0 && m == 0)
break;
for (int i = 0; i < n; ++i)
scanf("%d", &w[i]);
for (int i = 0; i < n; ++i)
scanf("%d", &c[i]);
memset(f, 0, sizeof(f));
f[0] = 1;
for (int i = 0; i < n; ++i) {
memset(sum,0,sizeof(sum));
for (int j = w[i]; j <= m; ++j)
if(!f[j] && f[j - w[i]] && sum[j - w[i]] < c[i]) {
f[j] = 1;
sum[j] = sum[j - w[i]] + 1;
}
}
int ans = 0;
for (int i = 1; i <= m; ++i)
if (f[i])
++ans;
printf("%d\n", ans);
}
return 0;
}