#include <iostream>
#include <algorithm>
#include <cmath>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <vector>
#include <cstring>
#include <numeric>
#include <cassert>
#include <iomanip>
using namespace std;
using str = string;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vs = vector<str>;
using vpl = vector<pair<ll,ll>>;
using sll = set<ll>;
using pll = pair<ll,ll>;
#define mset multiset
#define umap unordered_map
/*#include<ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using iset = tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>;
#define sAt(s,x) s.find_by_order(x) //Returns xth Iterator
#define sPos(s,x) s.order_of_key(x) //Return lower bound index*/
#define pus push_back
#define pub pop_back
#define in insert
#define ff first
#define ss second
#define sz(x) ((ll)(x).size())
#define all(x) x.begin(),x.end()
#define srt(x) sort(all(x))
#define srtd(x) sort(x.rbegin(),x.rend())
#define rev(x) reverse(all(x));
#define nextP(v) next_permutation(all(v))
#define Vmax(x) (*max_element(all(x)))
#define Vmin(x) (*min_element(all(x)))
#define Vsum(x) accumulate(all(x),0ll)
#define lowB(v,x) (lower_bound(all(v),x)-v.begin())
#define upB(v,x) (upper_bound(all(v),x)-v.begin())
#define cntB(x) (__builtin_popcountll(x))
#define cntC(s,x) ll(count(all(s),x))
#define For(n) for (ll i = 0; i < n; i++)
#define ForR(n) for (ll i = n-1; i >= 0; i--)
#define Forj(n) for (ll j = 0; j < n; j++)
#define For1(n) for (ll i = 1; i < n; i++)
#define Forl(x,y,z) for (ll x = y; x < z; x++)
#define nl cout << "\n";
#define endl "\n";
#define ya cout << "Yes\n"
#define na cout << "No\n"
#define prs(n) fixed << setprecision(n)
#define dbg(x) cout << #x << " = " << x << endl;
#define inpt(v) For(sz(v)) cin >> v[i];
#define prt(v) {for(auto &x:v) cout << x << ' '; nl}
const int M = 1e9+7; /*998244353;*/
const int N = 2e5+5;
const ld pi = 3.141592653589793238;
const ll INF = 2e18;
ll power(ll a,ll b) {ll r=1; while(b) {if(b&1) r=(r*a)%M; a=(a*a)%M; b/=2;} return r;}
vl sieve(ll n) {vl a(n+1,1),v; a[0]=a[1]=0; Forl(i,2,n+1) if(a[i]) {v.pus(i); for(ll j=2*i; j <=n; j+=i) a[j]=0;} return a;}
vl divsr(ll n) {vl a(n+1,1); For(n+1) a[i]=i; Forl(i,2,n+1) if(a[i]==i) {for(ll j=2*i; j<=n; j+=i) a[j]=i;} return a;}
vl fac(ll n) {vl v(n+1,1); Forl(i,2,n+1) v[i] = (v[i-1]*i)%M; return v;}
ll n, x, y, z, a, b, c, d, k, q, m; str s;
//---------------------------------------------------------------------------------------------------------------------------------
//Let's Go :)
void solve()
{
cin >> n >> k >> a >> b;
vpl p(n);
ll ans = 0, ezy = 0, hrd = 0, thard = 0, teasy = 0;
For(n) cin >> p[i].ss;
For(n) cin >> p[i].ff;
For(n)
if(p[i].ss) thard++;
else teasy++;
if(thard*b+teasy*a<=k)
{
cout << n; nl return;
}
srt(p);
for(auto &pr:p)
{
ll var = pr.ff-1, cnt = hrd+ezy;
var -= (hrd*b + ezy*a);
if(var>=0)
{
x = var/a;
x = min(x,teasy);
cnt += x;
var -= x*a;
x = var/b;
x = min(x,thard);
cnt += x;
ans = max(ans,cnt);
}
if(pr.ss) hrd++, thard--;
else ezy++, teasy--;
}
cout << ans; nl
}
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0);
int t = 1;
cin >> t;
while(t--) solve();
return 0;
}
766B - Mahmoud and a Triangle | 1618C - Paint the Array |
469A - I Wanna Be the Guy | 1294A - Collecting Coins |
1227A - Math Problem | 349A - Cinema Line |
47A - Triangular numbers | 1516B - AGAGA XOOORRR |
1515A - Phoenix and Gold | 1515B - Phoenix and Puzzle |
155A - I_love_username | 49A - Sleuth |
1541A - Pretty Permutations | 1632C - Strange Test |
673A - Bear and Game | 276A - Lunch Rush |
1205A - Almost Equal | 1020B - Badge |
1353A - Most Unstable Array | 770A - New Password |
1646B - Quality vs Quantity | 80A - Panoramix's Prediction |
1354B - Ternary String | 122B - Lucky Substring |
266B - Queue at the School | 1490A - Dense Array |
1650B - DIV + MOD | 1549B - Gregor and the Pawn Game |
553A - Kyoya and Colored Balls | 1364A - XXXXX |