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>
#define int long long
using namespace std;
const int nmax = 5e5 + 1;
struct str {
int a, b;
const bool operator < (str ult) const {
if(b != ult.b) {
return b < ult.b;
}
return a < ult.a;
}
} v[nmax];
bool f[nmax];
int32_t main() {
int n, ult = -1, ok = 1;
cin >> n;
set<str> ms;
for(int i = 1; i <= n; i ++) {
cin >> v[i].a >> v[i].b;
if(ult != -1 && v[i].b != ult) {
ok = 0;
}
ult = v[i].b;
}
if(ok == 1) {
int ans = 0;
sort(v + 1, v + n + 1);
for(int i = 1; i <= n; i ++) {
if(v[i].a != v[i - 1].a) {
ans ++;
}
}
cout << ans;
return 0;
}
for(int i = 1; i <= n; i ++) {
ms.insert({v[i].a, v[i].b});
}
int ans = 0;
while(!ms.empty()) {
auto it = ms.rbegin();
ans ++;
int ita = (*it).a, itb = (*it).b;
for(int i = 1; i <= n; i ++) {
if(!f[i] && abs(v[i].a - ita) <= itb - v[i].b) {
f[i] = 1;
if(ms.find({v[i].a, v[i].b}) != ms.end()) {
ms.erase({v[i].a, v[i].b});
}
}
}
}
cout << ans;
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... |