제출 #1138182

#제출 시각아이디문제언어결과실행 시간메모리
1138182fzyzzz_zTeam Contest (JOI22_team)C++20
46 / 100
20 ms2496 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; 
    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.end()) {
                    if ((*it).second < y) {
                        sy = y; 
                        sx = (*it).first; 
                    }
                }

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

                st.insert({x, y});
            } 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; 
                }
            }
        }


    }

    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...