Submission #361763

#TimeUsernameProblemLanguageResultExecution timeMemory
361763ritul_kr_singhCloud Computing (CEOI18_clo)C++14
100 / 100
1991 ms6764 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define pii pair<int, int> #define clock first #define core second.first #define price second.second signed main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); int n, m; cin >> n; pair<int, pii> comps[4000]; // clock rate, {core, price} pair<int, pii> ii; for(int j=0; j<n; ++j){ cin >> ii.core >> ii.clock >> ii.price; ii.price = -ii.price; comps[j] = ii; } cin >> m; for(int j=0; j<m; ++j){ cin >> ii.core >> ii.clock >> ii.price; ii.core = -ii.core; comps[n+j] = ii; } n += m; sort(comps, comps+n, greater<>()); int lim=(n)*50; int dp[2][lim+lim+1]; int ind = 1; for(int i=0; i<2; ++i){ for(int j=0; j<=lim; ++j){ dp[i][j] = -1e18; } dp[i][lim] = 0; for(int j=1; j<=lim; ++j){ dp[i][lim+j] = -1e18; } } int ans = -1e18; for(int x=1; x<=n; ++x){ ind = 1-ind; int i = ind; auto curr = comps[x-1]; for(int j=0; j<=lim+lim; ++j){ dp[i][j] = dp[!i][j]; } if(curr.core>=0){ for(int j=lim+curr.core; j<=lim+lim; ++j){ if(dp[!i][j-curr.core]>(int)-1e18) dp[i][j] = max(dp[i][j], dp[!i][j-curr.core]+curr.price); } }else{ curr.core = -curr.core; for(int j=lim+lim-curr.core; j+curr.core>=lim; --j){ if(dp[!i][j+curr.core]>(int)-1e18) dp[i][j] = max(dp[i][j], dp[!i][j+curr.core]+curr.price); } } } for(int j=0; j<=lim; ++j){ ans = max(ans, dp[ind][j+lim]); } cout << ans << "\n"; }
#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...