Submission #772134

#TimeUsernameProblemLanguageResultExecution timeMemory
772134Oscar123123Knapsack (NOI18_knapsack)C++17
73 / 100
1081 ms556 KiB
#include <bits/stdc++.h> using namespace std; int dp[2001]; bool vis[2001]; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); vis[0] = true; int S, N; cin >> S >> N; int ans = 0; for (int i = 0; i < N; ++i) { int v, w, k; cin >> v >> w >> k; for (int i = 2000; i >= 0; --i) { if (vis[i] >= 0) { for (int c = 1; c <= min((int)floor((S - i) / w), k); ++c) { dp[c * w + i] = max(dp[c * w + i], dp[i] + c * v); ans = max(ans, dp[c * w + i]); vis[c * w + i] = true; } } } } cout << ans << '\n'; }

Compilation message (stderr)

knapsack.cpp: In function 'int main()':
knapsack.cpp:13:24: warning: comparison of constant '0' with boolean expression is always true [-Wbool-compare]
   13 |             if (vis[i] >= 0) {
      |                 ~~~~~~~^~~~
#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...