# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1268676 | orzminhhc | Cloud Computing (CEOI18_clo) | C++20 | 334 ms | 2264 KiB |
#include <bits/stdc++.h>
using namespace std;
#define all(x) begin(x), end(x)
template<class T1, class T2>
bool maximize(T1 &a, T2 b){
if(a < b) {a = b; return true;}
return false;
}
template<class T1, class T2>
bool minimize(T1 &a, T2 b){
if(a > b) {a = b; return true;}
return false;
}
struct ITEM{
int c;
long long f,v;
int type;
};
bool cmp(const ITEM &a, const ITEM &b){
if(a.f != b.f) return a.f > b.f;
return a.type < b.type;
}
const long long inf = 1e18;
const int maxc = 2e5+5;
vector<long long> dp(maxc, -inf);
void solve(){
int n; cin >> n;
vector<ITEM> item;
for(int i = 0; i < n; i ++){
int c;
long long f, v;
cin >> c >> f >> v;
item.push_back({c,f,v,0});
}
int m; cin >> m;
for(int i = 0; i < m; i ++){
int c;
long long f,v; cin >> c >> f >> v;
item.push_back({c,f,v,1});
}
sort(all(item), cmp);
dp[0] = 0;
int cur_c = 0;
for(auto cur_item : item){
int c = cur_item.c, v = cur_item.v;
cur_c += c;
if(cur_item.type == 0){
for(int i = cur_c; i >= c; i --) if(dp[i-c] != -inf) maximize(dp[i], dp[i-c] - v);
}
else{
for(int i = 0; i <= cur_c - c; i++) if(dp[i+c] != -inf) maximize(dp[i], dp[i+c] + v);
}
}
long long res = 0;
for(int i = 0; i < maxc; i ++) maximize(res, dp[i]);
cout << res;
}
signed main(){
ios::sync_with_stdio(0); cin.tie(0);
if(fopen("A.inp", "r")){
freopen("A.inp","r", stdin);
freopen("A.out","w", stdout);
}
solve();
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... |