Submission #892503

#TimeUsernameProblemLanguageResultExecution timeMemory
892503viwlesxqTeam Contest (JOI22_team)C++17
100 / 100
89 ms11712 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define all(x) x.begin(), x.end() #define size(x) (int)x.size() template<class S, class T> bool chmin(S &a, const T &b) { return a > b && (a = b) == b; } template<class S, class T> bool chmax(S &a, const T &b) { return a < b && (a = b) == b; } const int inf = 1e9 + 7; const int INF = 1e18 + 7; const int mod = 998244353; struct person { int x, y, z; }; signed main() { cin.tie(nullptr)->sync_with_stdio(false); int n; cin >> n; person v[n]; vector<int> a, b, c; for (int i = 0; i < n; ++i) { cin >> v[i].x >> v[i].y >> v[i].z; a.push_back(i), b.push_back(i), c.push_back(i); } sort(all(a), [&](int &i, int &j) { return v[i].x < v[j].x; }); sort(all(b), [&](int &i, int &j) { return v[i].y < v[j].y; }); sort(all(c), [&](int &i, int &j) { return v[i].z < v[j].z; }); while (!a.empty() && !b.empty() && !c.empty()) { if (v[a.back()].y >= v[b.back()].y || v[a.back()].z >= v[c.back()].z) { a.pop_back(); continue; } if (v[b.back()].x >= v[a.back()].x || v[b.back()].z >= v[c.back()].z) { b.pop_back(); continue; } if (v[c.back()].x >= v[a.back()].x || v[c.back()].y >= v[b.back()].y) { c.pop_back(); continue; } if (a.back() == b.back()) { if (v[a.back()].x >= v[b.back()].y) { b.pop_back(); } else { a.pop_back(); } } else if (b.back() == c.back()) { if (v[b.back()].y >= v[c.back()].z) { c.pop_back(); } else { b.pop_back(); } } else if (a.back() == c.back()) { if (v[a.back()].x >= v[c.back()].z) { c.pop_back(); } else { a.pop_back(); } } else { cout << v[a.back()].x + v[b.back()].y + v[c.back()].z; 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...