# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
675530 | omikron123 | Cloud Computing (CEOI18_clo) | C++14 | 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 <cstdio>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstring>
using namespace std;
typedef long long ll;
// 1. 把computer和order放在一起处理,按频率排序,一个大列表。
// 2. dp[i][j],使用前i个的transaction的时候,如果剩下j个core时,最大的profit
// n,m <= 2000
int n, m;
struct T {
int c, f, v;
};
T tr[4005];
bool cmp(T &a, T &b) {return a.f > b.f;}
int C; // total cores
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d %d %d", &tr[i].c, &tr[i].f, &tr[i].v);
tr[i].v = -tr[i].v; // computers consume profit
C += tr[i].c;
}
scanf("%d", &m);
for (int i = n+1; i <= n+m; i++) {
scanf("%d %d %d", &tr[i].c, &tr[i].f, &tr[i].v);
tr[i].c = -tr[i].c; // orders consume cores
}
sort(tr+1, tr+n+m+1, cmp); // sort by decreasing frequency
vector<ll> dp(C+1, INT64_MIN), DP;
ll ans = 0;
dp[0] = 0;
for (int i=1; i <= n+m; i++) {
DP = dp;
for (int j=0; j <= C; j++) {
int J = j - tr[i].c;
if (J >= 0 && J <= C && dp[J] != INT64_MIN)
DP[j] = max(DP[j], dp[J] + tr[i].v);
if (i == n+m)
ans = max(ans, DP[j]);
}
swap(dp,DP);
}
printf("%lld", ans);
return 0;
}