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 ff first
#define ss second
#define all(a) a.begin(), a.end()
const int N = 2e5;
const int mod = 1e9 + 7;
signed main(){
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int n; cin >> n;
vector<array<int, 4> > w;
for(int i = 0;i < n; i++){
int c, f, cost; cin >> c >> f >> cost;
w.push_back({c, f, cost, 1});
}
int m; cin >> m;
for(int i = 0;i < m; i++){
int c, f, cost; cin >> c >> f >> cost;
w.push_back({c, f, cost, 0});
}
sort(all(w), [&](auto A, auto B){
if(A[1] == B[1]) return A[3] > B[3];
return A[1] > B[1];
});
vector<int> dp(N+5, -mod);
dp[0] = 0;
for(auto [c, f, cost, type] : w){
if(type == 1){
for(int i = N; i >= c; i--){
dp[i] = max(dp[i], dp[i-c] - cost);
}
}else{
for(int i = 1; i <= N - c; i++){
dp[i] = max(dp[i], dp[i+c] + cost);
}
}
}
cout << *max_element(all(dp));
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... |