This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int inf = 1e9;
int mn[305], mx[305];
int main() {
ios_base::sync_with_stdio(0), cin.tie(0);
int n;
cin >> n;
array<int, 3> a[n];
for (int i = 0; i < n; i++) {
cin >> a[i][0] >> a[i][1] >> a[i][2];
}
sort(a, a + n);
int ans = -1;
int cur = 0;
for (int i = 0; i < 305; i++) {
mn[i] = inf;
mx[i] = -inf;
}
int y = -1;
for (int i = 0; i < n; i++) {
while (a[cur][0] < a[i][0]) {
mx[a[cur][1]] = max(mx[a[cur][1]], a[cur][2]);
mn[a[cur][1]] = min(mn[a[cur][1]], a[cur][2]);
for (int newy = 304; newy > a[cur][1]; newy--) {
if (mn[newy] < a[cur][2]) {
y = max(y, newy);
break;
}
}
for (int newy = 0; newy < a[cur][1]; newy++) {
if (mx[newy] > a[cur][2]) {
y = max(y, a[cur][1]);
break;
}
}
cur++;
}
int sufxmx[305]{};
sufxmx[0] = mx[0];
for (int j = 1; j < 305; j++) {
sufxmx[j] = max(sufxmx[j - 1], mx[j]);
}
if (y >= max(1, a[i][1] + 1)) {
if (a[i][2] < sufxmx[y - 1]) {
ans = max(ans, a[i][0] + sufxmx[y - 1] + y);
}
}
}
cout << ans << '\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |