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 <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <algorithm>
#include <set>
using namespace std;
using ll = long long;
const ll NEGINF = -1e18;
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
vector<pair<int, pair<int, ll>>> transac(0);
while (n--)
{
int a, b;
ll c;
cin >> a >> b >> c;
transac.push_back({ b, {a, -c} });
}
cin >> n;
while (n--)
{
int a, b;
ll c;
cin >> a >> b >> c;
transac.push_back({ b, {-a, c} });
}
sort(transac.begin(), transac.end());
vector<ll> dp(1e5 + 1, NEGINF);
dp[0] = 0;
while (!transac.empty())
{
int numtadd = transac.back().second.first;
ll ptadd = transac.back().second.second;
transac.pop_back();
if (numtadd > 0) for (int inord = 1e5 - numtadd; inord > -1; inord--) dp[numtadd + inord] = fmax(dp[numtadd + inord], dp[inord] + ptadd);
else for (int inord = -numtadd; inord <= 1e5; inord++) dp[numtadd + inord] = fmax(dp[numtadd + inord], dp[inord] + ptadd);
}
ll ans = 0;
for (int inord = 0; inord <= 1e5; inord++) ans = fmax(ans, dp[inord]);
cout << ans;
}
# | 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... |