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;
typedef long long ll;
#define int long long
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
vector<int> c(n),f(n),v(n);
vector<tuple<int,int,int>> a;
int cnt=0;
for(int i=0;i<n;i++){
cin >> c[i] >> f[i] >> v[i];
a.push_back({f[i],c[i],v[i]});
cnt += c[i];
}
int m;
cin >> m;
vector<int> C(m),F(m),V(m);
for(int i=0;i<m;i++){
cin >> C[i] >> F[i] >> V[i];
a.push_back({F[i],C[i],-V[i]});
}
sort(a.rbegin(),a.rend());
vector<int> dp(cnt+1,-10000000000000);
dp[0] = 0;
for(auto [i,j,k] : a){
if(k > 0){
for(int l=j;l<=cnt;l++){
dp[l-j] = max(dp[l-j],dp[l]-k);
}
}
else{
for(int l=cnt-j;l>=0;l--){
dp[l+j] = max(dp[l+j],dp[l]-k);
}
}
}
sort(dp.rbegin(),dp.rend());
cout << dp[0] << "\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... |