Submission #1033295

#TimeUsernameProblemLanguageResultExecution timeMemory
1033295vjudge1Knapsack (NOI18_knapsack)C++17
73 / 100
1096 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; // Используем временный массив для обновления dp vector<int> temp_dp(dp); for (int j = w; j <= s; ++j) { for (int t = 1; t <= k && t * w <= j; ++t) { temp_dp[j] = max(temp_dp[j], dp[j - t * w] + t * v); } } dp = temp_dp; } 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...