Submission #636354

#TimeUsernameProblemLanguageResultExecution timeMemory
636354TUNGDUONGWILLWINVOI2023Knapsack (NOI18_knapsack)C++14
100 / 100
64 ms3616 KiB
#include <algorithm> #include <array> #include <bitset> #include <cassert> #include <chrono> #include <cmath> #include <cstring> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <vector> using namespace std; const int NAXM = 2e3 + 5; int S, N, dp[NAXM]; vector<vector<array<int, 2>>> a; int main() { // Coding scanf("%d%d", &S, &N); a.resize(S + 1); for (int i = 0; i < N; ++i) { int v, w, k; scanf("%d%d%d", &v, &w, &k); a[w].push_back({v, k}); } for (int i = 1; i <= S; ++i) { sort(a[i].begin(), a[i].end(), [&](const array<int, 2> &x, const array<int, 2> &y) { return x[0] > y[0]; }); } for (int i = 1; i <= S; ++i) { int id = 0; for (int j = 0; j < S / i; ++j) { if (id >= int(a[i].size())) { break; } for (int t = S - i; t >= 0; --t) { dp[t + i] = max(dp[t + i], dp[t] + a[i][id][0]); } --a[i][id][1]; if (!a[i][id][1]) { ++id; } } } int ans = 0; for (int i = 0; i <= S; ++i) { ans = max(ans, dp[i]); } printf("%d\n", ans); return 0; }

Compilation message (stderr)

knapsack.cpp: In function 'int main()':
knapsack.cpp:23:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |   scanf("%d%d", &S, &N);
      |   ~~~~~^~~~~~~~~~~~~~~~
knapsack.cpp:27:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |     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...