【題目敘述】http://codeforces.com/contest/1282/problem/C
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
struct prob{
int l, d;
};
int m, n, t, t_e, t_h, a[200005], b[200000], remain_e, remain_h, s, mx, tmp, cnt, score;
vector <prob> v;
bool cmp(prob x, prob y){
return x.d < y.d;
}
int main() {
cin >> m;
while (m--){
cin >> n >> t >> t_e >> t_h;
remain_e = 0;
remain_h = 0;
for (int i = 0; i < n; i++){
cin >> a[i];
if (a[i] == 1) remain_h++;
else remain_e++;
}
v.clear();
for (int i = 0; i < n; i++){
cin >> b[i];
v.push_back({a[i], b[i]});
}
v.push_back({0, t+1});
sort(v.begin(), v.end(), cmp);
mx = 0;
s = 0;
score = 0;
for (prob i:v){
if (s > t) break;
if (s < i.d){
tmp = i.d-s-1;
cnt = 0;
if (remain_e && tmp >= t_e){
cnt += min(remain_e, tmp/t_e);
tmp -= cnt * t_e;
}
if (remain_h && tmp >= t_h){
cnt += min(remain_h, tmp/t_h);
}
mx = max(mx, score+cnt);
}
if (i.l == 0){
s += t_e;
remain_e--;
}
else{
s += t_h;
remain_h--;
}
score++;
}
cout << mx << "\n";
}
}