이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define int ll
using pii = pair<int, int>;
 
struct node{
    int x, e;
};
 
signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
    int n; cin>>n;
    vector<node> t(n + 1);
    for (int i = 1; i <= n; i++){
        cin>>t[i].x>>t[i].e;
    }
    auto cmp = [&](node a, node b){
      	if (a.e == b.e){
          return a.x < b.x;
        }
        return (a.e > b.e);
    };
    sort(t.begin() + 1, t.end(), cmp);
    vector<int> d(n + 1), s(n + 1);
    for (int i = 1; i <= n; i++){
        d[i] = t[i].e - t[i].x;
        s[i] = t[i].e + t[i].x;
    }
    set<pii> s1, s2;
    for (int i = 1; i <= n; i++){
        s1.insert({d[i], i});
        s2.insert({s[i], i});
    }
    int out = 0;
    for (int i = 1; i <= n; i++){
        if (s1.empty() || s2.empty()) continue;
        if (s1.find({d[i], i}) == s1.end()){
            continue;
        }
        // xj <= xi and d[j] <= d[i]
        // xj > xi and s[j] <= s[i]
        vector<int> rem;
        auto it = s1.begin();
        while (it != s1.end()){
            auto [a, j] = *it;
            if (a > d[i]) break;
            if (t[j].x > t[i].x){
                it++;
                continue;
            }
            rem.push_back(j);
            it++;
        }
        it = s2.begin();
        while (it != s2.end()){
            auto [a, j] = *it;
            if (a > s[i]) break;
            if (t[j].x < t[i].x){
                it++;
                continue;
            }
            rem.push_back(j);
            it++;
        }
        for (int j: rem){
            auto it = s1.find({d[j], j});
            if (it != s1.end()) s1.erase(it);
            it = s2.find({s[j], j});
            if (it != s2.end()) s2.erase(it);
        }
        out++;
    }
    cout<<out<<"\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... |