Submission #1172429

#TimeUsernameProblemLanguageResultExecution timeMemory
1172429manowoKnapsack (NOI18_knapsack)C++20
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; const int M = 100004; const int N = 2004; vector<pair<int, int>> p; long long s, n, w, v, k, dp[N]; int main() { cin >> s >> n; if (n == 1) { cin >> v >> w >> k; cout << v * min(k, s / w) << endl; } else { for (int i = 0; i < n; i++) { cin >> v >> w >> k; while (k--) { p.pb({v, w}); } } for (auto [v, w] : p) { for (int j = s; j >= w; j--) { dp[j] = max(dp[j], dp[j - w] + v); } } long long ans = 0; for (int i = 1; i <= s; i++) { ans = max(ans, dp[i]); } cout << ans << endl; } return 0; }

Compilation message (stderr)

knapsack.cpp: In function 'int main()':
knapsack.cpp:19:19: error: 'class std::vector<std::pair<int, int> >' has no member named 'pb'
   19 |                 p.pb({v, w});
      |                   ^~