# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
70884 | georgerapeanu | Cloud Computing (CEOI18_clo) | C++11 | 413 ms | 1516 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 <cstdio>
#include <algorithm>
using namespace std;
const int NMAX = 2000;
const int CORE_MAX = 50;
const int TOTAL_CORE_MAX = 2 * NMAX * CORE_MAX;
const int COST_MAX = 1e9;
const long long TOTAL_COST_MAX = 2LL * NMAX * COST_MAX;
const long long inf = (1LL << 60) - TOTAL_COST_MAX - 3;
struct order_t{
int cores;
int frequency;
int cost;
order_t(){
cores = 0;
frequency = 0;
cost = 0;
}
bool operator < (const order_t &other)const{///this sorts them in nonincreasing order based on frequency
if(frequency != other.frequency){
return frequency > other.frequency;
}
if(cost != other.cost){
return cost < other.cost;
}
return cores < other.cores;
}
};
int n,m;
long long dp[TOTAL_CORE_MAX + 5];
int st,dr;
order_t orders[2 * NMAX + 5];
int main() {
fscanf(stdin,"%d",&n);
for(int i = 1;i <= n;i++){
fscanf(stdin,"%d %d %d",&orders[i].cores,&orders[i].frequency,&orders[i].cost);
orders[i].cost *= -1;
}
fscanf(stdin,"%d",&m);
for(int i = n + 1;i <= n + m;i++){
fscanf(stdin,"%d %d %d",&orders[i].cores,&orders[i].frequency,&orders[i].cost);
orders[i].cores *= -1;
}
n += m;
sort(orders + 1,orders + 1 + n);
for(int i = 0;i < n;i++){
if(orders[i + 1].cores < 0){
for(int j = max(0,st + orders[i + 1].cores);j < st;j++){
dp[j] = -inf;
}
for(int j = st;j <= dr;j++){
if(j + orders[i + 1].cores >= 0){
dp[j + orders[i + 1].cores] = max(dp[j + orders[i + 1].cores],dp[j] + orders[i + 1].cost);
}
}
}
else{
for(int j = dr + 1;j <= dr + orders[i + 1].cores;j++){
dp[j] = -inf;
}
for(int j = dr;j >= st;j--){
dp[j + orders[i + 1].cores] = max(dp[j + orders[i + 1].cores],dp[j] + orders[i + 1].cost);
}
dr += orders[i + 1].cores;
}
}
long long ans = 0;
for(int j = st;j <= dr;j++){
ans = max(ans,dp[j]);
}
fprintf(stdout,"%lld",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... |