# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1093334 | InvMOD | Cloud Computing (CEOI18_clo) | C++14 | 0 ms | 0 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>
using namespace std;
using ll = long long;
template<typename T> ckmx(T& a, const T& b){if(a < b) return a = b, true; return false;}
template<typename T> ckmn(T& a, const T& b){if(a > b) return a = b, true; return false;}
const int N = 2e3+5;
const ll INF = 1e9;
struct Computer{
int core, rate;
ll value;
// computer will < 0 and task will > 0
// computer has no harm with our dynamic programing :D
bool operator < (const Computer& q) const{
if(rate != q.rate){
return rate > q.rate;
}
else return value < q.value;
}
};
int n, m;
ll dp[2][50 * N];
Computer value[2 * N];
void solve()
{
cin >> n;
int total_core = 0;
for(int i = 1; i <= n; i++){
cin >> value[i].core >> value[i].rate >> value[i].value;
value[i].value = -value[i].value;
total_core = total_core + value[i].core;
}
cin >> m;
for(int i = n+1; i <= n+m; i++){
cin >> value[i].core >> value[i].rate >> value[i].value;
value[i].core = -value[i].core;
}
sort(value+1, value+1+n+m);
for(int i = 0; i < 2; i++){
fill(dp[i]+1, dp[i]+1+total_core, -INF);
}
for(int i = 1; i <= n+m; i++){
int pos = (i&1), pre = ((i&1)^1);
if(value[i].core > 0){
// is computer
//cout << value[i].core <<" " << value[i].value <<"\n";
for(int j = value[i].core; j <= total_core; j++){
ckmx(dp[pos][j], dp[pre][j - value[i].core] + value[i].value);
}
}
else{
// is task
int cur_core = -value[i].core;
//cout << cur_core << " " << value[i].value <<"\n";
for(int j = total_core - cur_core; j >= 0; j--){
ckmx(dp[pos][j], dp[pre][j + cur_core] + value[i].value);
}
}
for(int j = 0; j <= total_core; j++){
ckmx(dp[pos][j], dp[pre][j]);
}
}
ll answer = 0;
for(int i = 0; i < 2; i++){
for(int j = 0; j <= total_core; j++){
answer = max(answer, dp[i][j]);
}
}
cout << answer <<"\n";
}
int32_t main(){
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
#define name "InvMOD"
if(fopen(name".INP", "r")){
freopen(name".INP", "r", stdin);
freopen(name".OUT", "w", stdout);
}
solve();
return 0;
}