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;
using ll = long long;
using ii = pair<int, int>;
using aa = array<ll,3>;
const int N = 1e6+5;
const int INF = 1e9;
bool cmp(aa a,aa b) {
if(a[0]==b[0]) {
return a[1]<b[1];
}
else {
return a[0]>b[0];
}
}
aa a[10000];
ll dp[100005][2];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
int core=0;
for(int i=0;i<n;i++) {
cin >> a[i][2] >> a[i][0] >> a[i][1];
a[i][1]*=-1;
core+=a[i][2];
}
int m;
cin >> m;
for(int i=n;i<m+n;i++) {
cin >> a[i][2] >> a[i][0] >> a[i][1];
a[i][2]*=-1;
}
sort(a,a+n+m,cmp);
for(int i=1;i<=core;i++) dp[i][0]=-1e15;
dp[0][1]=0;
ll ans=-1e15;
for(int i=0;i<n+m;i++) {
for(int j=0;j<=core;j++) {
dp[j][1]=dp[j][0];
}
for(int j=0;j<=core;j++) {
if(j-a[i][2]>=0 && j-a[i][2]<=core) {
if(dp[j-a[i][2]][0]!=-1e15)
dp[j][1]=max(dp[j][1],dp[j-a[i][2]][0]+a[i][1]);
ans=max(ans,dp[j][1]);
}
//cout << dp[j][1] << ' ';
}
//cout << endl;
for(int j=0;j<=core;j++) {
dp[j][0]=dp[j][1];
}
}
cout << ans;
return 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... |