Submission #254308

#TimeUsernameProblemLanguageResultExecution timeMemory
254308MarcoMeijerCloud Computing (CEOI18_clo)C++14
100 / 100
2578 ms2324 KiB
#include <bits/stdc++.h> using namespace std; // macros typedef long long ll; typedef long double ld; typedef pair<int, int> ii; typedef pair<ll, ll> lll; typedef tuple<int, int, int> iii; typedef vector<int> vi; typedef vector<ii> vii; typedef vector<iii> viii; typedef vector<ll> vll; typedef vector<lll> vlll; #define REP(a,b,c) for(int a=int(b); a<int(c); a++) #define RE(a,c) REP(a,0,c) #define RE1(a,c) REP(a,1,c+1) #define REI(a,b,c) REP(a,b,c+1) #define REV(a,b,c) for(int a=int(c-1); a>=int(b); a--) #define FOR(a,b) for(auto& a : b) #define all(a) a.begin(), a.end() #define INF 1e18 #define EPS 1e-9 #define pb push_back #define popb pop_back #define fi first #define se second #define sz size() // input template<class T> void IN(T& x) {cin >> x;} template<class H, class... T> void IN(H& h, T&... t) {IN(h); IN(t...); } // output template<class T1, class T2> void OUT(const pair<T1,T2>& x); template<class T> void OUT(const T& x) {cout << x;} template<class H, class... T> void OUT(const H& h, const T&... t) {OUT(h); OUT(t...); } template<class T1, class T2> void OUT(const pair<T1,T2>& x) {OUT(x.fi," ",x.se);} template<class... T> void OUTL(const T&... t) {OUT(t..., "\n"); } //===================// // Added libraries // //===================// //===================// //end added libraries// //===================// void program(); int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); program(); } //===================// // begin program // //===================// const int MX = 2010; ll n, m; ll c[MX], f[MX], v[MX]; ll C[MX], F[MX], V[MX]; ll sa[MX], SA[MX]; vector<vector<vll>> dp; ll DP(ll i, ll j, ll k) { if(i < 0) return 0; if(j < 0) return 0; if(k > 50) return -INF; return dp[i%2][j][k]; } void program() { IN(n); RE(i,n) IN(c[i], f[i], v[i]); IN(m); RE(i,m) IN(C[i], F[i], V[i]); RE(i,n) sa[i]=i; sort(sa,sa+n,[](int i, int j) { return f[i]<f[j]; }); RE(i,m) SA[i]=i; sort(SA,SA+m,[](int i, int j) { return F[i]<F[j]; }); dp.resize(2); RE(i,2) { dp[i].resize(m+1); RE(j,m) dp[i][j].resize(51); } RE(i,n+1) RE(j,m) RE(k,51) { ll ans = DP(i,j-1,k); // dont give customer j her cores ans = max(ans,DP(i-1,j,k)); // dont buy computer i // give customer j her cores if(k >= C[SA[j]]) { ans = max(ans, DP(i,j-1,k-C[SA[j]]) + V[SA[j]]); } // buy computer i, and give customer j her cores if(i != 0 && f[sa[i-1]] >= F[SA[j]] && k+c[sa[i-1]] >= C[SA[j]]) { ans = max(ans, DP(i-1,j-1,k+c[sa[i-1]]-C[SA[j]]) - v[sa[i-1]] + V[SA[j]]); } // buy computer i if(i != 0 && f[sa[i-1]] >= F[SA[j]]) { ans = max(ans, DP(i-1,j,k+c[sa[i-1]])-v[sa[i-1]]); } dp[i%2][j][k] = ans; } OUTL(dp[n%2][m-1][0]); }
#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...