Submission #1104182

#TimeUsernameProblemLanguageResultExecution timeMemory
1104182micro7Knapsack (NOI18_knapsack)C++17
100 / 100
82 ms7240 KiB
#include <algorithm> #include <cstdio> #include <functional> #include <map> using namespace std; constexpr int MAXS = 2000; int n, s; map<int, map<int, int, greater<>>> m; int dp[MAXS + 1]; int main() { scanf("%d%d", &s, &n); for (int i = 0; i < n; ++i) { int v, w, k; scanf("%d%d%d", &v, &w, &k); m[w][v] += k; } for (auto &[w, v_cnt] : m) { for (int i = s; i >= w; --i) { int prv_w = i, profit = 0; for (auto [v, k] : v_cnt) { while (prv_w >= w && k) { prv_w -= w; profit += v; dp[i] = max(dp[i], dp[prv_w] + profit); --k; } if (prv_w < w) break; } } } printf("%d", dp[s]); return 0; }

Compilation message (stderr)

knapsack.cpp: In function 'int main()':
knapsack.cpp:13:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |   scanf("%d%d", &s, &n);
      |   ~~~~~^~~~~~~~~~~~~~~~
knapsack.cpp:16:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |     scanf("%d%d%d", &v, &w, &k);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~
#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...