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;
#define int long long
const int mod = 1e9+7;
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int n; cin >> n;
vector<array<int, 2>> a(n);
for(auto &[x, y]: a) cin >> x >> y;
sort(a.begin(), a.end());
vector<array<int, 3>> ar(n);
for(int i=0; i<n; i++){
ar[i] = {a[i][1], i, a[i][0]};
}
sort(ar.begin(), ar.end());
reverse(ar.begin(), ar.end());
vector<int> vis(n);
int ans = 0;
for(auto [x, y, z]: ar){
if(vis[y]) continue;
int l = y-1, r = y+1;
ans++;
while(r<n &&!vis[r] && abs(a[r][0]-z) <= x-a[r][1]){
vis[r] = 1;
r++;
}
while(l>=0 &&!vis[l] && abs(a[l][0]-z) <= x-a[l][1]){
vis[l] = 1;
l--;
}
}
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... |