Submission #1244266

#TimeUsernameProblemLanguageResultExecution timeMemory
1244266TobTeam Contest (JOI22_team)C++20
100 / 100
64 ms4516 KiB
#include <bits/stdc++.h> #define F first #define S second #define all(x) x.begin(), x.end() #define pb push_back #define FIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0) using namespace std; typedef long long ll; typedef pair <ll, ll> pii; const int N = 15e4 + 7; int n; int a[N], b[N], c[N], ia[N], ib[N], ic[N], bio[N]; int check(int x, int y, int z) { if (b[x] >= b[y] && b[x] >= b[z]) return 1; if (c[x] >= c[y] && c[x] >= c[z]) return 1; if (a[y] >= a[x] && a[y] >= a[z]) return 2; if (c[y] >= c[x] && c[y] >= c[z]) return 2; if (a[z] >= a[x] && a[z] >= a[y]) return 3; if (b[z] >= b[x] && b[z] >= b[y]) return 3; return 0; } int main () { FIO; cin >> n; for (int i = 0; i < n; i++) cin >> a[i] >> b[i] >> c[i], ia[i] = ib[i] = ic[i] = i; sort(ia, ia+n, [&](int x, int y){return a[x] < a[y];}); sort(ib, ib+n, [&](int x, int y){return b[x] < b[y];}); sort(ic, ic+n, [&](int x, int y){return c[x] < c[y];}); int x = n-1, y = n-1, z = n-1; while (x >= 0 && y >= 0 && z >= 0) { while (x >= 0 && bio[ia[x]]) x--; while (y >= 0 && bio[ib[y]]) y--; while (z >= 0 && bio[ic[z]]) z--; if (x < 0 || y < 0 || z < 0) break; int o = check(ia[x], ib[y], ic[z]); if (!o) break; if (o == 1) bio[ia[x]] = 1; if (o == 2) bio[ib[y]] = 1; if (o == 3) bio[ic[z]] = 1; } if (x < 0 || y < 0 || z < 0) cout << -1; else cout << a[ia[x]]+b[ib[y]]+c[ic[z]]; 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...