# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1093675 | luvna | Cloud Computing (CEOI18_clo) | C++14 | 216 ms | 1884 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<bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long ll;
template<class T> bool maximize(T& a, T b) {if(a < b) return a = b, true; return false;}
const int N = 2005;
const ll INF = 1e18;
struct computer{
int cores, rate, price;
bool operator < (const computer& a) const{
return (rate != a.rate) ? (rate > a.rate) : (cores > a.cores);
}
};
int n, m;
computer a[N];
vector<ll> dp;
void solve(){
cin >> n;
int max_cores = 0;
for(int i = 1; i <= n; i++){
int cores, rate, price; cin >> cores >> rate >> price;
a[i] = {cores, rate, -price};
max_cores += cores;
}
cin >> m;
for(int i = 1; i <= m; i++){
int cores, rate, price; cin >> cores >> rate >> price;
a[i+n] = {-cores, rate, price};
}
n += m;
sort(a + 1, a + 1 + n);
dp.resize(max_cores + 5, -INF);
dp[0] = 0;
for(int i = 1; i <= n; i++){
int cores = a[i].cores, p = a[i].price;
vector<ll> f = dp;
if(cores > 0){
//computer
//knapsack : f[i] = dp[i-cores] + p
for(int j = cores; j <= max_cores; j++){
f[j] = max(f[j], dp[j-cores] + 1LL*p);
}
}
else{
//task
//knapsack : f[i] = dp[i + cores] + p
cores = -cores;
for(int j = max_cores - cores; j > -1; j--){
f[j] = max(f[j], dp[j + cores] + 1LL*p);
}
}
dp = f;
}
ll ans = 0;
for(int i = 0; i <= max_cores; i++) maximize(ans, dp[i]);
cout << ans;
}
signed main(){
ios_base::sync_with_stdio(NULL);
cin.tie(0); cout.tie(0);
#define task "task"
if(fopen(task".INP", "r")){
freopen(task".INP", "r", stdin);
freopen(task".OUT", "w", stdout);
}
int t; t = 1; //cin >> t;
while(t--) solve();
}
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... |