Submission #799869

#TimeUsernameProblemLanguageResultExecution timeMemory
799869phoenixTeam Contest (JOI22_team)C++17
100 / 100
369 ms27148 KiB
#include<bits/stdc++.h>

using namespace std;
using ll = long long;


int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int n;
    cin >> n;
    set<pair<int, int>> xx, yy, zz;
    int x[n], y[n], z[n];
    for(int i = 0; i < n; i++) {
        cin >> x[i] >> y[i] >> z[i];
        xx.insert({x[i], i});
        yy.insert({y[i], i});
        zz.insert({z[i], i});
    }
    while(!xx.empty()) {
        int pos = (--xx.end())->second;
        if(y[pos] == (--yy.end())->first || z[pos] == (--zz.end())->first) {
            xx.erase({x[pos], pos}), yy.erase({y[pos], pos}), zz.erase({z[pos], pos});
            continue;
        }
        pos = (--yy.end())->second;
        if(x[pos] == (--xx.end())->first || z[pos] == (--zz.end())->first) {
            xx.erase({x[pos], pos}), yy.erase({y[pos], pos}), zz.erase({z[pos], pos});
            continue;
        }
        pos = (--zz.end())->second;
        if(x[pos] == (--xx.end())->first || y[pos] == (--yy.end())->first) {
            xx.erase({x[pos], pos}), yy.erase({y[pos], pos}), zz.erase({z[pos], pos});
            continue;
        }
        cout << (--xx.end())->first + (--yy.end())->first + (--zz.end())->first;
        return 0;
    }
    cout << -1;
}
#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...