Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- #define ll long long
- #define ld long double
- #define FOR(i, a, b) for(ll i=(a); i<=(b); i++)
- #define FORn(i, n) for(ll i=1; i<=(n); i++)
- #define FORx(i, a, b, n) for(ll i=(a); i<=(b); i+=(x))
- #define FORa(i, b) for(i; i<=(b); i++)
- #define FORax(i, b, x) for(i; i<=(b); i+=(x))
- #define FORR(i, a, b) for(ll i=(a); i>=(b); i--)
- #define FORRn(i, n) for(ll i=(n); i>=1; i--)
- #define FORRx(i, a, b, n) for(ll i=(a); i>=(b); i-=(x))
- #define FORRa(i, b) for(i; i>=(b); i--)
- #define FORRax(i, b, x) for(i; i>=(b); i-=(x))
- #define pub(a, x) (a).push_back(x)
- #define puf(a, x) (a).insert((a).begin(), x)
- #define pob(a) (a).pop_back()
- #define pof(a) (a).erase((a).begin())
- #define all(x) (x).begin(), (x).end()
- #define sz(x) (x).size()
- #define sqr(x) (x)*(x)
- #define PI (2*acos(0))
- using namespace std;
- struct cow
- {
- int p, h;
- };
- int n, d, res, j=1;
- bool tc(cow a, cow b){
- return a.p<b.p;
- }
- int main(){
- // freopen("INPUT.inp", "r", stdin);
- // freopen("OUTPUT.out", "w", stdout);
- // ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
- cin>>n>>d;
- vector<cow> a(n, {0, 0});
- vector<bool> m(n, 0);
- for(cow &i:a) cin>>i.p>>i.h;
- sort(all(a), tc);
- FOR(i, 0, n-3) FOR(j, i+1, n-2) if(a[j].p-a[i].p<=d){
- if(2*a[j].h<=a[i].h) m[j]=1;
- }
- else break;
- j=n-2;
- FORR(i, n-1, 2) FORR(j, i-1, 1) if(a[i].p-a[j].p<=d){
- if(2*a[j].h<=a[i].h&&m[j]==1) res++, m[j]=0;
- }
- else break;
- cout<<res;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement