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 min(A,B) (A<B?A:B)
#define max(A,B) (A>B?A:B)
using namespace std;
vector<long long>dp[4001];
void solve() {
int n;
cin>>n;
vector<vector<int> >a;
for(int i=0;i<n;i++) {
int f,v,c;
cin>>c>>f>>v;
a.push_back({f,c,-v});
}
int m;
cin>>m;
for(int i=0;i<m;i++) {
int f,v,c;
cin>>c>>f>>v;
a.push_back({f,-c,v});
}
sort(a.begin(),a.end());
dp[0]=vector<long long>(51,-(1e14));
dp[0][0]=0;
for(int i=1;i<=n+m;i++) {
int maxs=min(100000,50+50*min(i,n+m-i));
dp[i]=vector<long long>(maxs+1,-(1e14));
for(int negcores=0;negcores<=maxs;negcores++) {
if(negcores<dp[i-1].size())dp[i][negcores]=max(dp[i][negcores],dp[i-1][negcores]);
if(negcores+a[i-1][1]>=0 && negcores+a[i-1][1]<dp[i-1].size())
dp[i][negcores]=max(dp[i][negcores],dp[i-1][negcores+a[i-1][1]]+a[i-1][2]);
}
}
cout<<dp[n+m][0]<<endl;
}
int main() {
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
solve();
return 0;
}
Compilation message (stderr)
clo.cpp: In function 'void solve()':
clo.cpp:29:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
29 | if(negcores<dp[i-1].size())dp[i][negcores]=max(dp[i][negcores],dp[i-1][negcores]);
| ~~~~~~~~^~~~~~~~~~~~~~~
clo.cpp:30:59: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
30 | if(negcores+a[i-1][1]>=0 && negcores+a[i-1][1]<dp[i-1].size())
| ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~
# | 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... |