古今多少事,都付笑谈中.
#include<iostream>
using namespace std;
int t,n,k;
long long a[1010];
long long b[1010];
bool P(long long h){
long long tot=k;
for(int i=1;i<=n;i++){
long long temp=0;
if(b[i]<a[i]*h){
temp=a[i]*h-b[i];
}
tot-=temp;
if(tot<0) return 0;
}
return 1;
}
int main(){
std::ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>t;
while(t--){
cin>>n>>k;
for(int i=1;i<=n;i++){
cin>>a[i];
//cout<<a[i]<<endl;
}
for(int i=1;i<=n;i++){
cin>>b[i];
//cout<<b[i]<<endl;
}
long long l=0;
long long r=2e9;
while(l<=r){
long long mid=l+r>>1;
if(P(mid)){
l=mid+1;
}
else{
r=mid-1;
}
}
cout<<l-1<<endl;
}
}