0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-27 17:56:28 +00:00
OI-codes/POJ/1742/1742.cpp
2022-04-07 08:49:53 +08:00

37 lines
832 B
C++

#include <cstdio>
const int N = 105,
M = 1e6 + 5;
int n, m, v[N], s[N], g[M];
bool f[M];
int main() {
while (scanf("%d%d", &n, &m), n || m) {
for (int i = 1; i <= n; i++) {
scanf("%d", v + i);
}
for (int i = 1; i <= n; i++) {
scanf("%d", s + i);
}
for (int i = 1; i <= m; i++) f[i] = 0;
f[0] = 1;
for (int i = 1; i <= n; i++) {
for (int j = 0; j <= m; j++) g[j] = 0;
for (int j = v[i]; j <= m; j++) {
if (!f[j] && f[j - v[i]] && g[j - v[i]] < s[i]) {
f[j] = true;
g[j] = g[j - v[i]] + 1;
}
}
}
int ans = 0;
for (int i = 1; i <= m; i++) ans += f[i];
printf("%d\n", ans);
}
return 0;
}