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 endl '\n'
using namespace std;
typedef long long ll;
const int MAXN = 2e3 + 10;
const int MAXC = 50 + 10;
const int SUMC = MAXN * MAXC;
const int MAXF = 1e9 + 10;
const int MAXV = 1e9 + 10;
const ll INF = 4e18 + 10;
struct item
{
int rate;
int cores;
int cost;
bool type;
item()
{
rate = 0;
cores = 0;
cost = 0;
type = 0;
}
item(int _cores, int _rate, int _cost, bool _type)
{
cores = _cores;
rate = _rate;
cost = _cost;
type = _type;
}
friend bool operator<(item it1, item it2)
{
if(it1.rate == it2.rate)
return it1.type < it2.type;
return it1.rate > it2.rate;
}
};
int n, m;
vector < item > items;
ll dp[SUMC];
ll sum_cores;
void read()
{
cin >> n;
for(int i = 1; i <= n; i++)
{
int cores, rate, cost;
cin >> cores >> rate >> cost;
sum_cores += cores;
items.push_back(item(cores, rate, cost, 0));
}
cin >> m;
for(int i = 1; i <= m; i++)
{
int cores, rate, cost;
cin >> cores >> rate >> cost;
items.push_back(item(cores, rate, cost, 1));
}
}
void solve()
{
sort(items.begin(), items.end());
for(int i = 1; i <= sum_cores; i++)
{
dp[i] = -INF;
}
dp[0] = 0;
for(item it : items)
{
if(it.type == 0)
{
for(int i = sum_cores; i - it.cores >= 0; i--)
{
dp[i] = max(dp[i], dp[i - it.cores] - it.cost);
}
}
else
{
for(int i = 0; i + it.cores <= sum_cores; i++)
{
dp[i] = max(dp[i], dp[i + it.cores] + it.cost);
}
}
}
ll ans = -INF;
for(int i = 0; i <= sum_cores; i++)
{
ans = max(ans, dp[i]);
}
cout << ans << endl;
}
int main()
{
ios_base :: sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
read();
solve();
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... |