Submission #1242479

#TimeUsernameProblemLanguageResultExecution timeMemory
1242479chienthanminh23Cloud Computing (CEOI18_clo)C++17
0 / 100
3093 ms1092 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long struct Core { int freq, id; Core(int f, int i): freq(f), id(i) {} }; struct Order { int cores, minFreq; ll value; }; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n, m; cin >> n; vector<vector<Core>> machineCores(n); vector<int> machineCost(n); for (int i = 0; i < n; ++i) { int c, f, v; cin >> c >> f >> v; machineCost[i] = v; for (int j = 0; j < c; ++j) { machineCores[i].emplace_back(f, i); } } cin >> m; vector<Order> orders(m); for (int i = 0; i < m; ++i) { cin >> orders[i].cores >> orders[i].minFreq >> orders[i].value; } // Flatten all cores vector<Core> allCores; for (int i = 0; i < n; ++i) { for (auto& core : machineCores[i]) { allCores.push_back(core); } } // Sort by descending freq sort(allCores.begin(), allCores.end(), [](const Core& a, const Core& b) { return a.freq > b.freq; }); int totalCores = allCores.size(); ll maxProfit = 0; for (int mask = 0; mask < (1 << m); ++mask) { vector<Order> selected; ll totalValue = 0; int neededCores = 0; for (int i = 0; i < m; ++i) { if (mask & (1 << i)) { selected.push_back(orders[i]); totalValue += orders[i].value; neededCores += orders[i].cores; } } if (neededCores > totalCores) continue; vector<bool> used(totalCores, false); unordered_set<int> usedMachines; bool valid = true; int ptr = 0; for (auto& ord : selected) { int cnt = 0; for (int i = 0; i < totalCores && cnt < ord.cores; ++i) { if (!used[i] && allCores[i].freq >= ord.minFreq) { used[i] = true; usedMachines.insert(allCores[i].id); cnt++; } } if (cnt < ord.cores) { valid = false; break; } } if (!valid) continue; ll cost = 0; for (int id : usedMachines) { cost += machineCost[id]; } maxProfit = max(maxProfit, totalValue - cost); } cout << maxProfit << '\n'; return 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...