Submission #914407

#TimeUsernameProblemLanguageResultExecution timeMemory
914407Em1LKnapsack (NOI18_knapsack)C++17
0 / 100
3 ms348 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int, int>; using tiii = tuple<int, int, int>; int main() { ios::sync_with_stdio(0); cin.tie(0); freopen("input.txt", "r", stdin); int n, s; cin >> s >> n; vector < pii > val; for (int i = 1, v, w, k; i <= n; i++) { cin >> v >> w >> k; for (int p = 0; p <= 30; p++) if ((1 << p) <= k) { val.push_back({ v * (1 << p), w * (1 << p) }); k -= 1 << p; } } vector < int > dp(s + 1, -1); dp[0] = 0; for (auto [v, w] : val) { if (w > s) continue; for (int cur = s; cur >= w; cur--) if (dp[cur - w] >= 0) dp[cur] = max(dp[cur], dp[cur - w] + v); } cout << *max_element(dp.begin(), dp.end()) << "\n"; }

Compilation message (stderr)

knapsack.cpp: In function 'int main()':
knapsack.cpp:10:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   10 |     freopen("input.txt", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#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...