比赛 |
EYOI与SBOI开学欢乐赛1st |
评测结果 |
AAAAAAWWAA |
题目名称 |
双倍腹肌量 |
最终得分 |
80 |
用户昵称 |
ムラサメ |
运行时间 |
0.383 s |
代码语言 |
C++ |
内存使用 |
3.99 MiB |
提交时间 |
2022-08-29 21:58:42 |
显示代码纯文本
#include<bits/stdc++.h>
using namespace std;
struct node{
int x,y;
}a[100001];
int n,d,ans=0x7f7f;
priority_queue<int> que1;
priority_queue<int,vector<int>,greater<int> >que2;
bool cmp(node g1,node g2){
return g1.y<g2.y;
}
int main(){
freopen("double_muscle.in","r",stdin);
freopen("double_muscle.out","w",stdout);
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n>>d;
for(int i=1;i<=n;++i){
cin>>a[i].x>>a[i].y;
}
sort(a+1,a+1+n,cmp);
int j=1;
for(int i=2;i<=n;++i){
int down=a[i].y-d;
while(a[j].y<=down){
que1.push(a[j].x);
++j;
}
if(!que1.empty()){
while(que1.top()>a[i].x){
que2.push(que1.top());
que1.pop();
if(que1.empty()){
break;
}
}
}
if(!que2.empty()){
while(que2.top()<a[i].x){
que1.push(que2.top());
que2.pop();
if(que2.empty()){
break;
}
}
}
if(!que1.empty()){
ans=min(ans,a[i].x-que1.top());
}
if(!que2.empty()){
ans=min(ans,que2.top()-a[i].x);
}
}
if(ans<0x7f7f){
cout<<ans<<endl;
}
else{
cout<<"-1"<<endl;
}
return 0;
}