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>
#define int long long
#define fi first
#define se second
using namespace std;
const int maxN = 2005;
const int maxC = 2000 * 50 + 69;
const int inf = 1e9 + 10;
struct TCom{int c,f,v;};
int n,m;
int mark[maxN];
int f[maxC];
TCom a[maxN * 2];
bool cmp(TCom a, TCom b){
return a.f > b.f;
}
int32_t main()
{
ios_base::sync_with_stdio(); cin.tie(); cout.tie();
cin >> n;
for(int i = 1; i <= n; ++i)
cin >> a[i].c >> a[i].f >> a[i].v;
cin >> m;
for(int i = 1; i <= m; ++i)
cin >> a[i + n].c >> a[i + n].f >> a[i + n].v;
for(int i = 1; i <= n; ++i)
a[i].v = -a[i].v;
for(int i = n + 1; i <= n + m; ++i)
a[i].c = -a[i].c;
sort(a + 1, a + n + m + 1, cmp);
//for(int i = 1; i <= n + m + 1; ++i)
// cout << a[i].c << " " << a[i].f << " " << a[i].v << endl;
memset(f, 0, sizeof(f));
for(int i = n + m; i >= 1; --i){
if(a[i].v < 0){
for(int j = 0; j <= maxC; ++j)
if(j + a[i].c >= 0 && j + a[i].c <= maxC)
f[j] = max(f[j], f[j + a[i].c] + a[i].v);
}
else{
for(int j = maxC; j >= 0; --j)
if(j + a[i].c >= 0 && j + a[i].c <= maxC)
f[j] = max(f[j], f[j + a[i].c] + a[i].v);
}
}
cout << f[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... |