This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef pair<int,int> pi;
typedef vector<pi> pii;
#define REP(i,a,b) for(int i=a;i<b;i++)
#define F first
#define S second
#define PB push_back
#define MP make_pair
ll INF=1e18+10;
ll M=1e9+7;
int main() {
//ios::sync_with_stdio(0);
//cin.tie(0);
//freopen("test_input.txt", "r", stdin);
//freopen("test_output.txt", "w", stdout);
int n;cin>>n;
pii a(n);
REP(i,0,n)cin>>a[i].F>>a[i].S;
sort(a.begin(),a.end());
priority_queue<pi> pq;
REP(i,0,n)pq.push({a[i].S,i});
vi b(n,0);
int ans=0;
while(!pq.empty()){
int pos=pq.top().S;
pq.pop();
if(b[pos]==1)continue;
//cout<<pos<<" ";
b[pos]=1;
ans++;
int g=1;
while((pos-g>=0)&&(b[pos-g]==0)&&(a[pos].S-a[pos-g].S>=a[pos].F-a[pos-g].F)){
//cout<<pos-g<<" ";
b[pos-g]=1;
g++;
}
g=1;
while((pos+g<n)&&(b[pos+g]==0)&&(a[pos].S-a[pos+g].S>=a[pos+g].F-a[pos].F)){
b[pos+g]=1;
g++;
}
}
cout<<ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |