Submission #538706

#TimeUsernameProblemLanguageResultExecution timeMemory
538706kabikaKnapsack (NOI18_knapsack)C++14
37 / 100
131 ms262144 KiB
#include <iostream> #include <vector> #include <algorithm> #include <math.h> using namespace std; typedef long long ll; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int s, n; cin >> s >> n; vector<int> v, w; for (int i = 0; i < n; ++i) { int val, wt, k; cin >> val >> wt >> k; v.insert(v.end(), k, val); w.insert(w.end(), k, wt); } int sz = v.size(); vector<vector<int>> dp(sz + 1, vector<int>(s + 1, 0)); for (int i = 1; i <= sz; ++i) { for (int j = 1; j <= s; ++j) { dp[i][j] = dp[i - 1][j]; if (j >= w[i - 1]) dp[i][j] = max(dp[i - 1][j - w[i - 1]] + v[i - 1], dp[i][j]); } } cout << dp[sz][s] << '\n'; 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...