제출 #1034467

#제출 시각아이디문제언어결과실행 시간메모리
1034467vjudge1Cloud Computing (CEOI18_clo)C++17
100 / 100
305 ms1440 KiB
#include <bits/stdc++.h> #define ll long long using namespace std; struct isi { int core, clock, price, type; }; bool cmp(isi a, isi b) { if(a.clock != b.clock) return a.clock < b.clock; else return a.type > b.type; } int main() { int n; cin >> n; isi a[n]; int sum=0; vector<isi> barang; for(int i = 0; i < n; ++i){ cin >> a[i].core >> a[i].clock >> a[i].price, a[i].type = 0; sum+=a[i].core; barang.push_back(a[i]); } int m; cin >> m; isi b[m]; for(int i = 0; i < m; ++i){ cin >> b[i].core >> b[i].clock >> b[i].price, b[i].type = 1; barang.push_back(b[i]); } ll dp[sum + 1]; for(int q=1;q<=sum;q++){ dp[q]=-1e15; } dp[0] = 0; sort(barang.begin(), barang.end(), cmp); for(int q=barang.size()-1;q>=0;q--){ isi c=barang[q]; if(c.type == 0) { for(int i =sum; i >= c.core; --i) { dp[i] = max(dp[i], dp[i - c.core] - c.price); } } else { for(int i = 0; i + c.core <=sum; ++i) { dp[i] = max(dp[i], dp[i + c.core] + c.price); } } } ll res = 0; for(int i = 0; i <= sum; ++i) res = max(res, dp[i]); 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...