Dota2 Pro Circuit
题目传送门:
题目传送门
思路:
![请添加图片描述](https://img-blog.csdnimg.cn/c1e85c0785b34ef98190977b7a7fa0d1.jpg?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NTg0OTM5OA==,size_16,color_FFFFFF,t_70)
代码:
#include<bits/stdc++.h>
using namespace std;
const int maxn=5005;
struct node{
int h,p,resl,resr;
}a[maxn];
int b[maxn];
bool cmp(node x,node y){
return x.h<y.h;
}
bool cmp1(node x,node y){
return x.p<y.p;
}
int main(){
int T;
scanf("%d",&T);
while (T--){
int n;
scanf("%d",&n);
for (int i=1; i<=n; i++){
scanf("%d",&a[i].h);
a[i].p=i;
}
for (int i=1; i<=n; i++){
scanf("%d",&b[i]);
}
sort(a+1,a+1+n,cmp);
sort(b+1,b+1+n);
for (int i=1; i<=n; i++){
int maxh=a[i].h+b[n];
int l=0,lessp=0;
for (int j=n; j>=1; j--){
if (i!=j){
int tag=1;
while (b[l+1]+a[j].h<=maxh && l+1<n) l++,tag=0;
if (tag) {
if (lessp<l){
lessp++;
}
}
else {
lessp++;
}
}
}
a[i].resl=n-lessp;
int minh=a[i].h+b[1];
int r=n+1,morep=0;
for (int j=1; j<=n; j++){
if (i!=j){
int tag=1;
while (b[r-1]+a[j].h>minh && r-1>1) r--,tag=0;
if (tag){
if (n-r+1>morep){
morep++;
}
}
else morep++;
}
}
a[i].resr=morep+1;
}
sort(a+1,a+1+n,cmp1);
for (int i=1; i<=n; i++){
printf("%d %d\n",a[i].resl,a[i].resr);
}
}
}