求助(18分)
查看原帖
求助(18分)
886266
Anchedong楼主2023/5/28 15:31
//P3088 模拟
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N=50010;
struct cow {
	int x;
	int h;
};
cow c[N];
bool cmp(cow a,cow b) {
	return a.h>b.h;
}
int n,d,ans=0;
signed main(){
	cin>>n>>d;
	int i=n+1,j;
	while(--i!=0) cin>>c[n-i].x>>c[n-i].h;
	sort(c,c+n,cmp);
	for(i=n-1;i>=0;i--) {
		for(j = i - 1; j >= 0; j--) {
			if(abs(c[i].x-c[j].x)<=d&&c[j].h/2>=c[i].h){
				ans++; 
				break;
			}
		}
	}
	cout<<ans/2<<endl;
	return 0;
}
//AC PLEASE
2023/5/28 15:31
加载中...