Submission #578076

#TimeUsernameProblemLanguageResultExecution timeMemory
578076DL1234Knapsack (NOI18_knapsack)C++17
12 / 100
1 ms300 KiB
#include <iostream> #include <queue> using namespace std; struct item{ int p, w, n; float r; bool operator<(const item& o) const { return r <= o.r; } }; int main() { int s, n; cin >> s >> n; priority_queue<item> items; for (int i=0;i<n;i++){ item j; cin >> j.p >> j.w >> j.n; j.r = (float)j.p/(float)j.w; items.push(j); } int totalProfit = 0; int remainingWeight = s; while (items.size() != 0){ item i = items.top(); items.pop(); if (i.w > remainingWeight) continue; int maxNum = ((int)remainingWeight/(int)i.w) > i.n ? i.n : ((int)remainingWeight/(int)i.w); totalProfit += maxNum * i.p; remainingWeight = remainingWeight-(i.w*maxNum); } cout << totalProfit << 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...