# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
866237 | maks007 | Knapsack (NOI18_knapsack) | C++14 | 1052 ms | 348 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "bits/stdc++.h"
using namespace std;
//#define int long long
signed main () {
int W, n;
cin >> W >> n;
vector <int> v, w, k;
for(int i = 0; i < n; i ++) {
int V, WW;
cin >> V >> WW;
v.push_back(V);
w.push_back(WW);
int K;
cin >> K;
k.push_back(K);
}
vector <int> dp(W+1, -1e9);
dp[0] = 0;
for(int i = 0; i < v.size(); i ++) {
for(int j = W; j >= 0; j --) {
for(int K = 1; K <= k[i]; K ++) {
if(j-w[i]*K >= 0) dp[j] = max(dp[j-w[i]*K]+v[i]*K, dp[j]);
}
}
}
cout << *max_element(dp.begin(), dp.end());
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |