# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
312203 | BeanZ | Cloud Computing (CEOI18_clo) | C++14 | 2950 ms | 2296 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.
// I_Love_LPL
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
const int N = 2e3 + 5;
const int lim = 100;
ll dp[N][lim + 5];
struct viet{
ll c, f, v;
bool operator <(const viet& o) const{
return f > o.f;
}
}a[N], b[N];
ll c[N], v[N], f[N];
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
if (fopen("A.inp", "r")){
freopen("test.inp", "r", stdin);
freopen("test.out", "w", stdout);
}
ll n;
cin >> n;
for (int i = 1; i <= n; i++){
cin >> a[i].c >> a[i].f >> a[i].v;
}
for (int i = 0; i <= n; i++){
for (int j = 0; j <= lim; j++){
dp[i][j] = -1e18;
}
}
dp[0][0] = 0;
sort(a + 1, a + n + 1);
ll ans = 0;
ll m;
cin >> m;
for (int i = 1; i <= m; i++){
cin >> b[i].c >> b[i].f >> b[i].v;
}
sort(b + 1, b + m + 1);
/*
for (int j = 1; j <= n; j++){
/*
for (int k = 0; k <= 50; k++){
if (k >= a[j].c) dp[j][k] = max(dp[j][k], dp[j - 1][k - a[j].c] - a[j].v);
//cout << dp[j][k] << " " << j << " " << k << endl;
}
for (int k = 50; k >= 0; k--){
for (int i = 1; i <= m; i++){
if (k >= a[j].c) dp[j][k] = max(dp[j][k], dp[j - 1][k - a[j].c] - a[j].v);
if ((k + c[i]) <= 50 && f[i] <= a[j].f) dp[j][k] = max(dp[j][k], dp[j][k + c[i]] + v[i]);
ans = max(ans, dp[j][k]);
}
}
}*/
for (int i = 1; i <= n; i++) dp[i][a[i].c] = -a[i].v;
for (int i = 1; i <= m; i++){
//cout << dp[1][0] << endl;
for (int j = 1; j <= n; j++){
for (int k = 0; k <= lim; k++){
dp[j][k] = max(dp[j][k], dp[j - 1][k]);
if (k >= a[j].c) {
dp[j][k] = max(dp[j][k], dp[j - 1][k - a[j].c] - a[j].v);
}
}
for (int k = lim - 1; k >= 0; k--) dp[j][k] = max(dp[j][k], dp[j][k + 1]);
}
for (int j = n; j >= 1; j--){
//cout << dp[1][1] << endl;
for (int k = 0; k <= lim; k++){
//for (int i = 1; i <= m; i++){
//for (int k = 0; k <= 50; k++){
if ((k + b[i].c) <= lim && b[i].f <= a[j].f) dp[j][k] = max(dp[j][k], dp[j][k + b[i].c] + b[i].v);
ans = max(ans, dp[j][k]);
//cout << dp[j][k] << " " << j << " " << k << endl;
//}
}
}
//cout << dp[3][80] << endl;
}
cout << ans;
}
/*
3
6 4 3
45 5 3
35 4 1
3
43 3 5
31 4 4
34 3 3
*/
Compilation message (stderr)
# | 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... |