Submission #927872

#TimeUsernameProblemLanguageResultExecution timeMemory
927872OAleksaTeam Contest (JOI22_team)C++14
64 / 100
2016 ms256268 KiB
#include <bits/stdc++.h> using namespace std; #define f first #define s second const int N = 2e5 + 69; const int A = 4010; const int inf = 1e9; int n, a[N], b[N], c[N], d[A][A]; int gmx[A][A], gmn[A][A], mn[A][A]; map<int, int> ca, cb, cc; signed main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int tt = 1; //cin >> tt; while (tt--) { cin >> n; vector<int> x, y, z; for (int i = 1;i <= n;i++) { cin >> a[i] >> b[i] >> c[i]; x.push_back(a[i]); y.push_back(b[i]); z.push_back(c[i]); } sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end()); sort(y.begin(), y.end()); y.erase(unique(y.begin(), y.end()), y.end()); sort(z.begin(), z.end()); z.erase(unique(z.begin(), z.end()), z.end()); for (int i = 1;i <= n;i++) { auto u = lower_bound(x.begin(), x.end(), a[i]) - x.begin() + 1; ca[u] = a[i]; a[i] = u; u = lower_bound(y.begin(), y.end(), b[i]) - y.begin() + 1; cb[u] = b[i]; b[i] = u; u = lower_bound(z.begin(), z.end(), c[i]) - z.begin() + 1; cc[u] = c[i]; c[i] = u; } for (int i = 0;i < A;i++) { for (int j = 0;j < A;j++) { gmn[i][j] = inf; gmx[i][j] = -inf; d[i][j] = -inf; mn[i][j] = inf; } } for (int i = 1;i <= n;i++) { gmx[a[i]][b[i]] = max(c[i], gmx[a[i]][b[i]]); gmn[a[i]][b[i]] = min(c[i], gmn[a[i]][b[i]]); } for (int i = 1;i < A;i++) { for (int j = 1;j < A;j++) { d[i][j] = max({d[i][j - 1], d[i - 1][j], gmx[i][j]}); mn[i][j] = min(mn[i][j - 1], gmn[i][j]); } } int ans = -1; for (int i = 1;i <= n;i++) { for (int j = a[i] + 1;j < (n > 4000 ? 1000 : A);j++) { if (mn[j][b[i] - 1] < d[j - 1][b[i] - 1] && d[j - 1][b[i] - 1] > c[i]) { ans = max(ans, cb[b[i]] + ca[j] + cc[d[j - 1][b[i] - 1]]); } } } 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...