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
struct Computer{
int c, f, v;
Computer (int _c=0, int _f=0, int _v=0): c(_c), f(_f), v(_v){}
bool operator<(const Computer &b){
return f<b.f;
}
};
const int N=2010, inf=1e18;
int f[N*50];
int n, m;
Computer a[N];
vector<pair<int, int>> vv[N];
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n;
for (int i=1; i<=n; ++i) cin >> a[i].c >> a[i].f >> a[i].v;
sort(a+1, a+n+1);
cin >> m;
for (int i=1; i<=m; ++i){
Computer b;
cin >> b.c >> b.f >> b.v;
if (b.f>a[n].f) continue;
vv[lower_bound(a+1, a+n+1, b)-a].emplace_back(b.c, b.v);
}
for (int i=0; i<N*50; ++i) f[i]=-inf;
f[0]=0;
for (int i=n; i>=1; --i){
int mx=0;
for (int j=(n-i)*50; j>=0; --j) f[j+a[i].c]=max(f[j+a[i].c], f[j]-a[i].v);
for (int j=0; j<=(n-i)*50; ++j) if (f[j]!=-inf) mx=j;
for (auto &j:vv[i]){
int c=j.first, v=j.second;
for (int k=c; k<=mx; ++k) if (f[k]!=-inf) f[k-c]=max(f[k-c], f[k]+v);
}
}
cout << *max_element(f, f+n+1) << '\n';
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... |