对于一个数,最大得分时要加上b[1],最小得分加上b[n].
寻找最大排名,要对每个b[2->n]匹配一个a[y],使尽可能多的和小于b[1] + a[x]
显然从小到大枚举b[i],依次在a中找即可
const int maxn = 5e3 + 7;
int n, t, m;
int a[maxn], b[maxn], bp[maxn], wp[maxn];
vector<pair<int, int>> va;
void solve() {
cin >> t;
while (t--) {
cin >> n;
va.clear();
for (int i = 1; i <= n; i++)
cin >> a[i], va.emplace_back(a[i], i);
sort(all(va));
reverse(all(va));
for (int i = 1; i <= n; i++)
cin >> b[i];
queue<int> que;
for (int i = 0; i < n; i++) {
while (!que.empty()) que.pop();
for (int k = n; k >= 1; k--)
que.push(b[k]);
int bstsoc = va[i].first + b[1];
int bstpl = n;
for (auto &j:va) {
if (j.second == va[i].second) continue;
if (j.first + que.front() <= bstsoc) bstpl--, que.pop();
}
bp[va[i].second] = bstpl;
while (!que.empty()) que.pop();
for (int k = 1; k <= n; k++)
que.push(b[k]);
int wstsoc = va[i].first + b[n];
int wstpl = 1;
for (int p = n - 1; p >= 0; p--) {
auto &j = va[p];
if (j.second == va[i].second) continue;
if (j.first + que.front() > wstsoc) wstpl++, que.pop();
}
wp[va[i].second] = wstpl;
}
for (int i = 1; i <= n; i++)
cout << bp[i] << " " << wp[i] << endl;
}
}