# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1268958 | minhtan1103 | Cloud Computing (CEOI18_clo) | C++17 | 444 ms | 2064 KiB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxN = 4e3 + 5;
const int maxV = 1e5 + 5;
const ll INF = 1e18 + 5;
struct Ed{
int c, f, v, id;
Ed(){c = f = v = id = 0;}
Ed(int c_, int f_, int v_, int id_){
c = c_; f = f_; v = v_; id = id_;
}
};
bool cmp(Ed x, Ed y){
if (x.f == y.f) return x.id > y.id;
return x.f > y.f;
}
int n, m, sum;
Ed a[maxN];
ll dp[2][maxV];
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
if (fopen("CLOUD.INP", "r")){
freopen("CLOUD.INP", "r", stdin);
freopen("CLOUD.OUT", "w", stdout);
}
cin >> n;
for (int i = 1; i <= n; ++i){
cin >> a[i].c >> a[i].f >> a[i].v;
a[i].id = 1;
}
cin >> m;
for (int i = n + 1; i <= n+m; ++i){
cin >> a[i].c >> a[i].f >> a[i].v;
a[i].id = 0;
}
sort(a+1, a+n+m+1, cmp);
for (int j = 0; j < maxV; ++j){
dp[0][j] = dp[1][j] = -INF;
}
ll ans = -INF;
dp[0][0] = 0;
for (int i = 1; i <= n+m; ++i){
int cur = i%2;
int prv = 1-cur;
for (int j = 0; j < maxV; ++j) dp[cur][j] = -INF;
if (a[i].id){
for (int j = 0; j <= sum; ++j){
dp[cur][j] = max(dp[cur][j], dp[prv][j]);
ans = max(ans, dp[cur][j]);
if (j + a[i].c >= 0 && dp[prv][j] != -INF){
dp[cur][j+a[i].c] = max(dp[cur][j+a[i].c], dp[prv][j] - a[i].v);
ans = max(ans, dp[cur][j+a[i].c]);
}
}
sum += a[i].c;
}
else{
for (int j = 0; j <= sum; ++j){
dp[cur][j] = max(dp[cur][j], dp[prv][j]);
ans = max(ans, dp[cur][j]);
if (j - a[i].c >= 0 && dp[prv][j] != -INF){
dp[cur][j-a[i].c] = max(dp[cur][j-a[i].c], dp[prv][j] + a[i].v);
ans = max(ans, dp[cur][j-a[i].c]);
}
}
}
}
cout << ans;
return 0;
}
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... |