제출 #1138186

#제출 시각아이디문제언어결과실행 시간메모리
1138186fzyzzz_zTeam Contest (JOI22_team)C++20
46 / 100
22 ms2492 KiB
#include <bits/stdc++.h>
using namespace std;

using ll = long long;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int n; 
    cin >> n; 
    map<int, vector<pair<int, int>>> f; 
    for (int i = 0; i < n; ++i) {
        int x, y, z; 
        cin >> x >> y >> z; 
        f[x].push_back({y, z}); 
    }

    set<pair<int, int>> st, ts; 
    int sx = -1, sy = -1; 

    int ans = -1; 
    for (auto & [d1, v]: f) {
        for (auto [x, y]: v) {
            if (x < sx && y < sy) {
                ans = max(ans, d1 + sx + sy); 
            }
        }

        for (auto [x, y]: v) {
            if (x >= sx && y >= sy) {
                if (st.find({x, y}) != st.end()) continue; 
                
                auto it = st.upper_bound({x, y}); 

                if (it != st.begin()) {
                    it--; 
                    if ((*it).second > y) {
                        sx = x; 
                        sy = (*it).second; 
                    }
                } 

                auto ti = ts.upper_bound({y, x}); 

                if (ti != ts.begin()) {
                    ti--; 
                    if ((*ti).second > x) {
                        sy = y; 
                        sx = (*ti).second; 
                    }
                }

                st.insert({x, y});
                ts.insert({y, x}); 
            } else if (x > sx) {
                sx = x; 
            } else if (y > sy) {
                sy = y; 
            }
            while (st.size()) {
                auto [x, y] = *st.begin(); 
                if (x <= sx && y <= sy) {
                    st.erase(st.begin()); 
                } else {
                    break; 
                }
            }
            while (ts.size()) {
                auto [y, x] = *st.begin(); 
                if (x <= sx && y <= sy) {
                    ts.erase(ts.begin()); 
                } else {
                    break; 
                }
            }
        }


    }

    cout << ans << "\n"; 


    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...