제출 #975631

#제출 시각아이디문제언어결과실행 시간메모리
975631vjudge1Knapsack (NOI18_knapsack)C++17
12 / 100
1 ms348 KiB
#include <iostream> #include <vector> #include <algorithm> using namespace std; struct Cake { int value; int weight; int quantity; }; bool cmp(const Cake& a, const Cake& b) { return (double)a.value / a.weight > (double)b.value / b.weight; } int main() { int S, N; cin >> S >> N; vector<Cake> cakes(N); for (int i = 0; i < N; i++) { cin >> cakes[i].value >> cakes[i].weight >> cakes[i].quantity; } sort(cakes.begin(), cakes.end(), cmp); int maxValue = 0; int remainingWeight = S; for (const Cake& cake : cakes) { int maxQuantity = min(cake.quantity, remainingWeight / cake.weight); maxValue += maxQuantity * cake.value; remainingWeight -= maxQuantity * cake.weight; } cout << maxValue << endl; 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...