Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
1.2 kB
2
Indexable
Never
// y.ha
#include <bits/stdc++.h>
#define cook '\n'
#define maxn 50005
using namespace std;
int n,d,L[maxn],R[maxn],save[maxn],a[maxn];
pair<int,int> c[maxn];

bool check(int x,int y) {
    return abs(c[x].first - c[y].first) <= d ;
}
int solve() {
    save[0] = 0;
    int top = 0;
    for ( int i = 1; i <= n; i++ ) {
        while ( 2*a[i] > a[save[top]] ) top--;
        if ( check(i,save[top]) && top!= 0 ) L[i] = 1 ;
        save[++top] = i;
    }
    top = 0 ;
    save[0] = n+1;
    for ( int i = n; i >= 1; i-- ) {
        while ( 2*a[i] > a[save[top]] ) top--;
        if ( check(i,save[top]) && top!= 0 ) R[i] = 1;
        save[++top] = i ;
    }
    int dem = 0 ;
    for ( int i = 1; i<=n; i++ )
        if ( L[i] + R[i] == 2 ) dem++ ;
    return dem ;
}

int main()
{
    ios_base::sync_with_stdio(0) ;
    cin.tie(nullptr) ;
    if(fopen("bai1.inp","r"))
        freopen("bai1.inp","r",stdin) ;
    cin >> n >> d;
    for ( int i = 1; i <= n; i++ ) cin >> c[i].first >> c[i].second ;
    a[0] = a[n+1] = 2e9 + 5;
    for ( int i = 1; i <= n; i++ ) a[i] = c[i].second ;
    cout << solve() ;
}
Leave a Comment