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 ar array
typedef int64_t ll;
#define int ll
const int inf = 1e18;
signed main(){
ios::sync_with_stdio(0); cin.tie(0);
int n; cin>>n;
vector<ar<int, 2>> a(n);
for(int i=0;i<n;i++){
cin>>a[i][0]>>a[i][1]>>a[i][1];
}
int m; cin>>m;
vector<ar<int, 2>> b(m);
for(int i=0;i<m;i++){
cin>>b[i][0]>>b[i][1]>>b[i][1];
}
sort(a.begin(), a.end(), [&](auto& a, auto& b){
return a[1] < b[1];
});
sort(b.begin(), b.end(), [&](auto& a, auto& b){
return a[1] < b[1];
});
vector<int> dp(n * 50 + 1, inf), tp(m * 50 + 1);
dp[0] = 0;
for(auto x : a){
for(int i=n*50-x[0];~i;i--){
dp[i + x[0]] = min(dp[i + x[0]], dp[i] + x[1]);
}
}
for(auto x : b){
for(int i=m*50-x[0];~i;i--){
tp[i + x[0]] = max(tp[i + x[0]], tp[i] + x[1]);
}
}
for(int i=n*50-1;~i;i--){
dp[i] = min(dp[i], dp[i + 1]);
}
int res = 0;
for(int i=0;i<=m*50;i++){
res = max(res, tp[i] - dp[i]);
}
cout<<res<<"\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... |