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; int dp [2][5010*50];
struct rac {
int f, ku, v;
};
vector < rac > k;
int cmp (rac a, rac b){
if (a.f==b.f){
if (a.ku>b.ku) return 1;
return 0;
}
if (a.f>b.f) return 1;
return 0;
}
int main(){
int n,m; cin >> n;
for (int i=0; i<n; i++) {
int c,f,v; cin >> c >> f >> v; v=(-v);
rac x; x.ku=c; x.f=f; x.v=v;
k.push_back(x);
}
cin >> m;
for (int i=0; i<m; i++) {
int c,f,v; cin >> c >> f >> v; c=(-c);
rac x; x.ku=c; x.f=f; x.v=v;
k.push_back(x);
}
int sol=0;
sort (k.begin(), k.end(), cmp);
for (int j=1; j<5010*50; j++) dp[0][j]=-1e9;
for (int i=0; i<k.size(); i++) {
for (int j=0; j<5010*50; j++) {
if (j<k[i].ku) dp[1][j]=dp[0][j];
else if (j-k[i].ku>=5010*50) dp[1][j]=dp[0][j];
else dp [1][j] = max (dp[0][j-k[i].ku]+k[i].v, dp[0][j]);
}
for (int j=0; j<5010*50; j++) dp[0][j]=dp[1][j];
}
for (int j=0; j<5010*50; j++) sol=max (sol, dp[0][j]);
cout << sol;
return 0;
}
Compilation message (stderr)
clo.cpp: In function 'int main()':
clo.cpp:31:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<rac>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
31 | for (int i=0; i<k.size(); i++) {
| ~^~~~~~~~~
# | 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... |