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 int long long
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int n; cin >> n;
vector<array<int, 3>> comp(n);
for(auto &[c, f, v]: comp) cin >> c >> f >> v;
sort(comp.begin(), comp.end(), [&](auto i, auto j){
return i[1] > j[1];
});
vector<int> val(n*50+2, (int)-1e18);
val[0] = 0;
int m; cin >> m;
vector<array<int, 3>> cust(m);
for(auto &[c, f, v]: cust) cin >> c >> f >> v;
sort(cust.begin(), cust.end(), [&](auto i, auto j){
return i[1] > j[1];
});
int pos=0, s=val.size()-1;
for(int i=0; i<m; i++){
while(pos<n && comp[pos][1] >= cust[i][1]){
for(int j=s; j>=0; j--){
if(val[j]==(int)-1e18) continue;
int v = j+comp[pos][0];
val[v] = max(val[v], val[j] - comp[pos][2]);
}
pos++;
}
for(int j=cust[i][0]; j<=s; j++){
val[j-cust[i][0]] = max(val[j-cust[i][0]], val[j]+cust[i][2]);
}
}
int ans = 0;
for(auto i: val) ans=max(ans, i);
cout << ans;
}
# | 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... |