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 pair<int, int> pll;
#define fastio ios::sync_with_stdio(false), cin.tie(0)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) (x).begin(), (x).end()
#define pb push_back
#define eb emplace_back
#define f first
#define s second
const int maxn = 2e5 + 5;
int main(void){
fastio;
int n;
cin>>n;
vector<pll> a;
map<int, int> mp;
for(int i = 0; i < n; i++){
int x, y;
cin>>x>>y;
mp[x] = max(mp[x], y);
}
for(auto [x, y] : mp) a.eb(x, y);
n = a.size();
vector<int> cov(n, 1);
int mx = a[0].s;
for(int i = 1; i < n; i++){
mx -= a[i].f - a[i - 1].f;
if(mx >= a[i].s) cov[i] = 0;
else mx = a[i].s;
}
mx = a[n - 1].s;
for(int i = n - 2; i >= 0; i--){
mx -= a[i + 1].f - a[i].f;
if(mx >= a[i].s) cov[i] = 0;
else mx = a[i].s;
}
cout<<accumulate(ALL(cov), 0)<<"\n";
}
# | 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... |