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;
const int maxn = 500005;
int n;
struct resident
{
int e;
int x;
};
resident a[maxn];
bool cmp(resident p, resident q)
{
return p.e > q.e;
}
void fastIO()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
int main()
{
fastIO();
cin >> n;
for (int i = 1; i <= n; ++i)
{
cin >> a[i].x >> a[i].e;
}
sort(a + 1, a + n + 1, cmp);
set<pair<int, int>> smaller;
set<pair<int, int>> bigger;
int ans = 0;
for (int i = 1; i <= n; ++i)
{
bool covered = false;
auto it = smaller.lower_bound(make_pair(a[i].e - a[i].x, 0));
if (it != smaller.end() && it->second >= a[i].x)
{
covered = true;
}
auto it2 = bigger.lower_bound(make_pair(a[i].e + a[i].x, 0));
if (it2 != bigger.end() && it2->second <= a[i].x)
{
covered = true;
}
if (covered == false)
{
++ans;
smaller.insert(make_pair(a[i].e - a[i].x, a[i].x));
bigger.insert(make_pair(a[i].e + a[i].x, a[i].x));
}
}
cout << ans << endl;
return 0;
}
# | 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... |