제출 #1050401

#제출 시각아이디문제언어결과실행 시간메모리
1050401antonCloud Computing (CEOI18_clo)C++17
100 / 100
1281 ms3404 KiB
#include<bits/stdc++.h> using namespace std; #define int long long #define pii pair<int, int> const int INF = 1e18; int N, M; struct PT{ int c, f, v; PT(int _c, int _f, int _v){ c= _c; f= _f; v = _v; } bool operator<(const PT &b)const{ return f>b.f; } }; vector<PT> computers; vector<PT> orders; void chm(int& i, int v){ i = max(i, v); } signed main(){ cin>>N; for(int i = 0; i<N; i++){ int c, f, v; cin>>c>>f>>v; computers.push_back(PT(c, f, v)); } cin>>M; for(int i = 0; i<M; i++){ int c, f, v; cin>>c>>f>>v; orders.push_back(PT(c, f, v)); } sort(computers.begin(), computers.end()); sort(orders.begin(), orders.end()); vector<vector<vector<int>>> dp(2, vector<vector<int>>(M+1, vector<int>(51, -INF))); dp[0][0][0] = 0; for(int cur_comp = 0; cur_comp<=N; cur_comp++){ dp[(cur_comp+1)%2] = vector<vector<int>>(M+1, vector<int>(51, -INF)); for(int cur_order = 0; cur_order<=M; cur_order++){ for(int stock = 0; stock <=50; stock++){ int cur_v= dp[(cur_comp)%2][cur_order][stock]; if(cur_comp<N){ chm(dp[(cur_comp+1)%2][cur_order][stock], cur_v); } if(cur_order<M){ chm(dp[(cur_comp)%2][cur_order+1][stock], cur_v); } if(cur_order<M && stock>=orders[cur_order].c){ chm(dp[(cur_comp)%2][cur_order+1][stock-orders[cur_order].c], cur_v +orders[cur_order].v); } if(cur_comp<N && cur_order<M){ if(computers[cur_comp].f>=orders[cur_order].f){ if(stock+computers[cur_comp].c>=orders[cur_order].c && stock+computers[cur_comp].c-orders[cur_order].c<=50){ chm(dp[(cur_comp+1)%2][cur_order+1][stock-orders[cur_order].c+computers[cur_comp].c], cur_v +orders[cur_order].v - computers[cur_comp].v); } else if(stock+computers[cur_comp].c<=50){ chm(dp[(cur_comp+1)%2][cur_order][stock+computers[cur_comp].c], cur_v - computers[cur_comp].v); } } } } } } int res= 0; for(int i = 0; i<=50; i++){ res =max(dp[N%2][M][i], res); } cout<<res<<endl; }
#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...