AcWing 782. 避嫌抢劫
原题链接
中等
作者:
_empty
,
2019-05-14 19:37:44
,
所有人可见
,
阅读 744
#include<iostream>
#include<algorithm>
#include<set>
using namespace std;
const int N=200010;
typedef pair<int,int> PII;
PII banks[N];
int main()
{
int n,min_dist;
cin>>n>>min_dist;
for(int i=1;i<=n;i++) cin>>banks[i].first>>banks[i].second;
sort(banks+1,banks+1+n);
int res=0;
for(int j=0,i=1,maxv=0;i<=n;i++ )
{
while(j+1<i && banks[i].first-banks[j+1].first>=min_dist)
{
j++;
maxv=max(maxv,banks[j].second);
}
res=max(res,banks[i].second+maxv);
}
cout<<res<<endl;
return 0;
}