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>
#include <iostream>
#define ll long long
#define s second
#define pb push_back
#define f first
using namespace std;
const int N = 100005;
vector<pair<pair<int,int>,int> > vec;
int tot;
ll dpold[N],dpnew[N];
bool cmp(pair<pair<int,int>,int> a, pair<pair<int,int>,int> b){
if (a.f.s < b.f.s) return 0;
if (a.f.s > b.f.s) return 1;
return (a.f.f > b.f.f);
}
signed main() {
int n;
cin>>n;
for (int i = 0; i < n; i++){
int c,f,v;
cin>>c>>f>>v;
tot += c;
vec.pb({{c,f},-v});
}
int m;
cin>>m;
for (int i = 0; i < m; i++){
int c,f,v;
cin>>c>>f>>v;
vec.pb({{-c,f},v});
}
sort(vec.begin(),vec.end(),cmp);
for (int i = 1;i <= tot; i++)
dpold[i] = dpnew[i] = -1e18;
for (int i = 0; i < vec.size(); i++){
int pr = vec[i].s,cr = vec[i].f.f;
for (int j = 0; j <= tot; j++){
int nw = j + cr;
if (nw < 0 || nw > tot || dpold[j] == -1e18) continue;
dpnew[nw] = max(dpnew[nw], dpold[j] + pr);
}
for (int j = 0; j <= tot; j++)
dpold[j] = dpnew[j];
}
ll ans=0;
for (int j = 0; j <= tot; j++)
ans=max(ans,dpold[j]);
cout<<ans;
}
Compilation message (stderr)
clo.cpp: In function 'int main()':
clo.cpp:41:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<std::pair<int, int>, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
41 | for (int i = 0; i < vec.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... |