| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1319072 | aaaaaaaa | Cloud Computing (CEOI18_clo) | C++20 | 0 ms | 0 KiB |
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(), x.end()
#defint int long long
vector<vector<int>> v;
signed main(){
ios::sync_with_stdio(0);
cin.tie(nullptr); cout.tie(nullptr);
int n, m, cores = 0; cin >> n;
for(int i = 0, a, b, c; i < n; ++i){
cin >> a >> b >> c;
v.push_back({b, 1, a, c});
cores += a;
}
cin >> m;
for(int i = 0, a, b, c; i < m; ++i){
cin >> a >> b >> c;
v.push_back({b, 0, a, c});
cores += a;
}
sort(all(v));
vector<int> dp(cores + 5, 0);
for(int i = 0; i < v.size(); ++i){
vector<int> ndp(cores + 5, 0);
for(int j = 0; j <= cores; ++j){
ndp[j] = dp[j];
if(v[i][1] == 0){
if(j + v[i][2] <= cores) ndp[j] = max(ndp[j], (int) dp[j + v[i][2]] - v[i][3]);
}else{
if(v[i][2] <= j){
ndp[j] = max(ndp[j], (int) dp[j - v[i][2]] + v[i][3]);
}
}
}
swap(dp, ndp);
}
cout << dp[0] << "\n";
return 0;
}
