# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
866234 | maks007 | Knapsack (NOI18_knapsack) | C++14 | 203 ms | 262144 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;
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 = min(k , W/WW);
k--;
while(k --) {
v.push_back(V);
w.push_back(WW);
}
}
vector <int> dp(W+1, -1e9);
dp[0] = 0;
for(int i = 0; i < v.size(); i ++) {
for(int j = W; j >= 0; j --) {
if(j-w[i] >= 0) dp[j] = max(dp[j], dp[j-w[i]]+v[i]);
}
}
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... |