Submission #927959

#TimeUsernameProblemLanguageResultExecution timeMemory
927959OAleksaTeam Contest (JOI22_team)C++14
100 / 100
1119 ms66060 KiB
#include <bits/stdc++.h> using namespace std; #define f first #define s second const int N = 2e5 + 69; int n, a[N], b[N], c[N], vis[N], u; multiset<int> x, y, z; signed main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int tt = 1; //cin >> tt; while (tt--) { cin >> n; multiset<tuple<int, int, int>> st1, st2, st3; multiset<tuple<int, int, int, int>> ev; for (int i = 1;i <= n;i++) { cin >> a[i] >> b[i] >> c[i]; st1.insert({a[i], b[i], i}); st2.insert({a[i], c[i], i}); st3.insert({b[i], c[i], i}); ev.insert({a[i], b[i], c[i], i}); x.insert(a[i]); y.insert(b[i]); z.insert(c[i]); } while (!x.empty()) { auto mx = *x.rbegin(); auto my = *y.rbegin(); auto mz = *z.rbegin(); auto u1 = st1.lower_bound({mx, my, -1}); auto u2 = st2.lower_bound({mx, mz, -1}); auto u3 = st3.lower_bound({my, mz, -1}); auto u4 = ev.lower_bound({mx, my, mx, -1}); if (u1 != st1.end() && get<0>(*u1) == mx && get<1>(*u1) == my) { int i = get<2>(*u1); x.erase(x.find(a[i])); y.erase(y.find(b[i])); z.erase(z.find(c[i])); st1.erase(st1.find({a[i], b[i], i})); st2.erase(st2.find({a[i], c[i], i})); st3.erase(st3.find({b[i], c[i], i})); ev.erase(ev.find({a[i], b[i], c[i], i})); vis[i] = 1; } else if (u2 != st2.end() && get<0>(*u2) == mx && get<1>(*u2) == mz) { int i = get<2>(*u2); x.erase(x.find(a[i])); y.erase(y.find(b[i])); z.erase(z.find(c[i])); st1.erase(st1.find({a[i], b[i], i})); st2.erase(st2.find({a[i], c[i], i})); st3.erase(st3.find({b[i], c[i], i})); ev.erase(ev.find({a[i], b[i], c[i], i})); vis[i] = 1; } else if (u3 != st3.end() && get<0>(*u3) == my && get<1>(*u3) == mz) { int i = get<2>(*u3); x.erase(x.find(a[i])); y.erase(y.find(b[i])); z.erase(z.find(c[i])); st1.erase(st1.find({a[i], b[i], i})); st2.erase(st2.find({a[i], c[i], i})); st3.erase(st3.find({b[i], c[i], i})); ev.erase(ev.find({a[i], b[i], c[i], i})); vis[i] = 1; } else if (u4 != ev.end() && get<0>(*u4) == mx && get<1>(*u4) == my && get<2>(*u4) == mz) { int i = get<3>(*u4); x.erase(x.find(a[i])); y.erase(y.find(b[i])); z.erase(z.find(c[i])); st1.erase(st1.find({a[i], b[i], i})); st2.erase(st2.find({a[i], c[i], i})); st3.erase(st3.find({b[i], c[i], i})); ev.erase(ev.find({a[i], b[i], c[i], i})); vis[i] = 1; } else break; } int ans = -1; int mx = 0, my = 0, mz = 0; for (int i = 1;i <= n;i++) { if (!vis[i]) { u++; mx = max(mx, a[i]); my = max(my, b[i]); mz = max(mz, c[i]); } } if (u > 2) ans = mx + my + mz; 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...