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;
pair<pair<int, int>, int> a[4005];
long long dp[100005], tmp[100005];
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, m;
cin >> n;
for (int i=1; i<=n; i++)
{
cin >> a[i].first.second >> a[i].first.first >> a[i].second;
a[i].second*=-1;
}
cin >> m;
for (int i=n+1; i<=n+m; i++)
{
cin >> a[i].first.second >> a[i].first.first >> a[i].second;
a[i].first.second*=-1;
}
sort(a+1, a+n+m+1, greater<pair<pair<int, int>, int> >());
for (int i=1; i<=1e5; i++)
dp[i]=-1e18;
for (int i=1; i<=n+m; i++)
{
for (int j=0; j<=1e5; j++)
{
if (j-a[i].first.second>=0 && j-a[i].first.second<=1e5)
tmp[j]=max(dp[j], dp[j-a[i].first.second]+a[i].second);
else
tmp[j]=dp[j];
}
for (int j=0; j<=1e5; j++)
dp[j]=tmp[j];
}
long long ans=0;
for (int i=0; i<=1e5; i++)
ans=max(ans, dp[i]);
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... |