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
const int maxx=-1e15;
struct compu
{
int c,f,w;
};
bool cmp(compu a, compu b)
{
return (a.f>b.f||(a.f==b.f&&a.c>b.c));
}
vector<compu>v;
int dp[200005];
int dq[200005];
int n,q;
main()
{
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin>>n;
for(int i=1;i<=n;i++){
int c,f,w;
cin>>c>>f>>w;
v.push_back({c,f,-w});
}
cin>>q;
for(int i=1;i<=q;i++){
int c,f,w;
cin>>c>>f>>w;
v.push_back({-c,f,w});
}
sort(v.begin(),v.end(),cmp);
for(int i=0;i<=50*n+1;i++)dp[i]=maxx;
for(int i=0;i<=50*n;i++)dq[i]=maxx;
dp[0]=0;
dq[0]=0;
for(int i=0;i<v.size();i++){
for(int j=0;j<=50*n;j++) {
int neww=j+v[i].c;
if(0<=neww&&neww<=50*n)dq[neww]=max(dq[neww],dp[j]+v[i].w);
}
for(int j=0;j<=50*n;j++)dp[j]=dq[j];
}
int res=0;
for(int i=0;i<=50*n;i++)res=max({res,dp[i],dq[i]});
cout<<res;
return 0;
}
Compilation message (stderr)
clo.cpp:18:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
18 | main()
| ^~~~
clo.cpp: In function 'int main()':
clo.cpp:38:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<compu>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
38 | for(int i=0;i<v.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... |