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;
using ll = long long;
using pii = pair<int, int>;
#define pb push_back
#define ff first
#define ss second
#define ins insert
#define arr3 array<int, 3>
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n; cin>>n;
vector<arr3> f(n + 1);
for (int i = 1; i <= n; i++){
cin>>f[i][0]>>f[i][1]>>f[i][2];
}
sort(f.begin() + 1, f.end());
vector<int> a(n + 1, -1);
int i = 1, out = -1;
while (i <= n){
int j = i;
while (j <= n && f[i][0] == f[j][0]){
j++;
}
int mx = -1;
for (int t = i; t < j; t++){
for (int k = 1; k < i; k++){
if (a[k] == -1) continue;
if (f[k][1] > f[t][1] && (a[k] - f[k][1]) > f[t][2]){
mx = max(mx, a[k]);
}
}
}
for (int t = i; t < j; t++){
for (int k = 1; k < j; k++){
if (f[k][1] > f[t][1] && f[k][2] < f[t][2]){
a[k] = max(a[k], f[k][1] + f[t][2]);
}
if (f[t][1] > f[k][1] && f[t][2] < f[k][2]){
a[t] = max(a[i], f[t][1] + f[k][2]);
}
}
}
if (mx != -1) out = max(out, f[i][0] + mx);
i = j;
}
cout<<out<<"\n";
}
# | 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... |