C++#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int KmaxN = 1e5 + 5;
int _;
int ans = 0;
int ret = 0;
int lst = 0;
bool vis[KmaxN];
ll n, m;
ll L, V;
ll ce[KmaxN];
struct node {
ll d, v, a;
bool operator < (const node & other) const {
return d > other.d;
}
}p[KmaxN];
int erfen(int need) {
int l = 1, r = m;
while (l <= r) {
int mid = (l + r) >> 1;
if (ce[mid] == need) {
return mid;
}
else if (ce[mid] >= need && ce[mid - 1] < need) {
return mid;
}
else if (ce[mid] < need) {
l = mid + 1;
}
else {
r = mid - 1;
}
}
return 1;
}
void solve_AllZero() {
ans = 0;
for (int i = 1; i <= n; ++i) {
if (p[i].v > V && p[i].d <= ce[m]) {
ans++;
}
}
if (ans == 0) {
cout << ans << " " << m << '\n';
}
else {
cout << ans << " " << m - 1 << '\n';
}
}
void solve_All_OverZero() {
ans = 0;
for (int i = 1; i <= n; ++i) {
if (p[i].d > ce[m]) {
continue;
}
ll vt2 = p[i].v * p[i].v + 2 * p[i].a * (ce[m] - p[i].d);
if (vt2 > V * V) {
ans++;
}
}
if (ans == 0) {
cout << ans << " " << m << '\n';
}
else {
cout << ans << " " << m - 1 << '\n';
}
}
void solve_All_UnderZero() {
ans = 0;
ret = 0;
lst = m + 1;
sort(p + 1, p + n + 1);
for (int i = 1; i <= n; ++i) {
if (p[i].d > ce[m]) {
continue;
}
if (p[i].v <= V) {
continue;
}
int k = erfen(p[i].d);
if (p[i].v * p[i].v + 2 * p[i].a * (ce[k] - p[i].d) > V * V) {
ans++;
}
else {
continue;
}
if (2 * p[i].a * (ce[lst] - p[i].d) + p[i].v * p[i].v > V * V) {
continue;
}
else {
ret++;
lst = k;
}
}
cout << ans << " " << m - ret << "\n";
}
void solve() {
ans = 0;
ret = 0;
lst = m + 1;
int f = 0;
int ma = 0;
sort(p + 1, p + n + 1);
for (int i = 1; i <= n; ++i) {
if (p[i].a == 0) {
if (p[i].v > V && p[i].d <= ce[m]) {
ans++;
}
continue ;
}
if (p[i].a > 0) {
if (p[i].d > ce[m]) {
continue;
}
ll vt2 = p[i].v * p[i].v + 2 * p[i].a * (ce[m] - p[i].d);
if (vt2 > V * V) {
ans++;
vis[i] = true;
}
continue;
}
if (p[i].d > ce[m]) {
continue;
}
if (p[i].v <= V) {
continue;
}
int k = erfen(p[i].d);
if (p[i].v * p[i].v + 2 * p[i].a * (ce[k] - p[i].d) > V * V) {
ans++;
}
else {
continue;
}
if (2 * p[i].a * (ce[lst] - p[i].d) + p[i].v * p[i].v > V * V) {
continue;
}
else {
ret++;
lst = k;
if (ret == 1) {
ma = k;
}
}
}
if (ret == 0) {
if (ans == 0) {
cout << ans << " " << m << '\n';
}
else {
cout << ans << " " << m - 1 << '\n';
}
return ;
}
for (int i = 1; i <= n; ++i) {
if (vis[i] == false) {
continue;
}
if (p[i].a <= 0) {
continue;
}
if (p[i].d > ce[m]) {
continue;
}
if (p[i].d > ce[ma]) {
f = 1;
break;
}
ll vt2 = p[i].v * p[i].v + 2 * p[i].a * (ce[ma] - p[i].d);
if (vt2 <= V * V) {
f = 1;
break;
}
}
cout << ans << " " << m - ret - f << "\n";
}
void solve_the_problem() {
bool ling = true;
bool zheng = true;
bool fu = true;
cin >> n >> m >> L >> V;
for (int i = 1; i <= n; ++i) {
ll d, v, a;
cin >> d >> v >> a;
p[i] = {d, v, a};
if (a == 0) {
fu = false;
zheng = false;
}
else if (a > 0) {
ling = false;
fu = false;
}
else {
ling = false;
zheng = false;
}
}
for (int i = 1; i <= m; ++i) {
cin >> ce[i];
vis[i] = false;
}
ce[m + 1] = 1e8;
if (ling == true) {
solve_AllZero();
return ;
}
else if (zheng == true) {
solve_All_OverZero();
return ;
}
else if (fu == true) {
solve_All_UnderZero();
return ;
}
else {
solve();
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
cin >> _;
while (_--) {
solve_the_problem();
}
return 0;
}
/*
对于所有的a_i都等于0,看看有几个超速的,如果有至少一个超速的
那么只需要留一个测速仪
否则全部删掉
对于所有的a_i都>0,只需要看看他们到最后一个测速仪有没有超速
如果有超速的,那么测速仪只需要留最后一个
否则全部删掉
对于所有的a_i都<0,先将他们按照d从大到小排序,对于第i辆车
二分找到第一个能使它超速的,然后看看下一个这个能不能使它超速
不能就继续找
对于测试点1,2使用分类讨论
等等吧,先写上前三个
*/