Submission #1033290

#TimeUsernameProblemLanguageResultExecution timeMemory
1033290vjudge1Knapsack (NOI18_knapsack)C++17
73 / 100
1033 ms600 KiB
#include <bits/stdc++.h> using namespace std; #define int long long void solve() { int s, n; cin >> s >> n; vector<int> dp(s + 1, 0); for (int i = 0; i < n; i++) { int v, w, k; cin >> v >> w >> k; for (int b = 1; k > 0; b *= 2) { int num = min(b, k); k -= num; int tv = num * v; int tw = num * w; for (int j = s; j >= tw; j--) { dp[j] = max(dp[j], dp[j - tw] + tv); } } } cout << *max_element(dp.begin(), dp.end()) << '\n'; } signed main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); solve(); return 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...