Submission #976644

#TimeUsernameProblemLanguageResultExecution timeMemory
976644vjudge1Knapsack (NOI18_knapsack)C++17
12 / 100
1 ms348 KiB
#include <iostream> #include <algorithm> using namespace std; struct Kue { long long value, weight, stock; }; int main() { int s, n; long long ans = 0; cin >> s >> n; Kue kue[n]; for (int i = 0; i < n; i++) { cin >> kue[i].value >> kue[i].weight >> kue[i].stock; } sort(kue, kue + n, [](const Kue &a, const Kue &b) { return a.value * b.weight > b.value * a.weight; }); int k; for (int i = 0; i < n; i++) { if (kue[i].weight > s) continue; k = min(s / kue[i].weight, kue[i].stock); ans += k * kue[i].value; s -= k * kue[i].weight; } cout << ans; }
#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...