1 #include<iostream>
 2 using namespace std;
 3 int cnt[100001];
 4 bool  f[100001];
 5 typedef struct{
 6     int value,num;    
 7 }S;
 8 S coin[110];
 9 int main()
10 {
11     int n,m;
12     int i,j,k,count;
13     while(scanf("%d%d",&n,&m)!=EOF)
14     {
15         if(n==0&&m==0break;
16         for(i=0;i<n;i++)
17         scanf("%d",&coin[i].value);
18         for(i=0;i<n;i++)
19         scanf("%d",&coin[i].num);
20         for(i=1;i<=m;i++)
21         f[i]=false;
22         f[0]=true;
23         count=0;
24         for(i=0;i<n;i++)
25         {
26             for(j=0;j<=m;j++)
27             cnt[j]=0;
28             for(j=coin[i].value;j<=m;j++)
29             {
30                 if(!f[j]&&f[j-coin[i].value]&&cnt[j-coin[i].value]<coin[i].num)// key point 
31                 {cnt[j]=cnt[j-coin[i].value]+1;f[j]=true;count++;}    //here we use cnt[] to
32                                             //record the num of coins
33                                             // of this kind has used;
34             }    
35         }
36         printf("%d\n",count);    
37     }    
38     return 0;    
39 }
40