Submission #976642

#TimeUsernameProblemLanguageResultExecution timeMemory
976642vjudge1Knapsack (NOI18_knapsack)C++17
Compilation error
0 ms0 KiB
#include <iostream> 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 i = 0, 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; }

Compilation message (stderr)

knapsack.cpp: In function 'int main()':
knapsack.cpp:17:5: error: 'sort' was not declared in this scope; did you mean 'qsort'?
   17 |     sort(kue, kue + n, [](const Kue &a, const Kue &b) {
      |     ^~~~
      |     qsort
knapsack.cpp:21:9: warning: unused variable 'i' [-Wunused-variable]
   21 |     int i = 0, k;
      |         ^