Submission #70884

#TimeUsernameProblemLanguageResultExecution timeMemory
70884georgerapeanuCloud Computing (CEOI18_clo)C++11
100 / 100
413 ms1516 KiB
#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)

clo.cpp: In function 'int main()':
clo.cpp:44:11: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     fscanf(stdin,"%d",&n);
     ~~~~~~^~~~~~~~~~~~~~~
clo.cpp:47:13: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
       fscanf(stdin,"%d %d %d",&orders[i].cores,&orders[i].frequency,&orders[i].cost);
       ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
clo.cpp:51:11: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     fscanf(stdin,"%d",&m);
     ~~~~~~^~~~~~~~~~~~~~~
clo.cpp:54:13: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
       fscanf(stdin,"%d %d %d",&orders[i].cores,&orders[i].frequency,&orders[i].cost);
       ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...