# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
915634 | pan | Cloud Computing (CEOI18_clo) | C++17 | 0 ms | 0 KiB |
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>
//#include "bits_stdc++.h"
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define input(x) scanf("%lld", &x);
#define print(x, y) printf("%lld%c", x, y);
#define show(x) cerr << #x << " is " << x << endl;
#define show2(x,y) cerr << #x << " is " << x << " " << #y << " is " << y << endl;
#define show3(x,y,z) cerr << #x << " is " << x << " " << #y << " is " << y << " " << #z << " is " << z << endl;
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ld, ll> pd;
typedef pair<string, ll> psl;
typedef pair<ll, ll> pi;
typedef pair<ll, pi> pii;
ll n, m;;
struct order
{
ll c, f, v;
};
ll const INF = 1e15;
bool compare(order a, order b)
{
if (a.f==b.f) return a.c>0
return a.f>b.f;
}
int main()
{
input(n);
vector<order> orders(n);
ll maxc = 0;
for (ll i=0; i<n; ++i) {input(orders[i].c); input(orders[i].f); input(orders[i].v); orders[i].v=-orders[i].v; maxc += orders[i].c;}
input(m);
orders.resize(n+m);
for (ll i=n; i<n+m; ++i) {input(orders[i].c); input(orders[i].f); input(orders[i].v); orders[i].c=-orders[i].c; }
sort(orders.begin(), orders.end(), compare);
//for (ll i=0; i<n+m; ++i){ cout << orders[i].c << endl;}
ll size1 = maxc;
vector<ll> prevv(maxc+5, -INF);
prevv[0] = 0;
ll ans = 0;
for (ll i=0; i<n+m; ++i)
{
//show(i);
vector<ll> dp(maxc+5, -INF);
for (ll j=0; j<=size1; ++j)
{
dp[j] = prevv[j];
if (j-orders[i].c>=0 && j-orders[i].c<=size1 && prevv[j-orders[i].c]!=-INF) dp[j] = max(dp[j], prevv[j-orders[i].c] + orders[i].v);
ans = max(ans, dp[j]);
//show2(j, dp[j]);
//show(j-orders[i].c);
}
swap(dp, prevv);
}
cout << ans << endl;
return 0;
}