# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1092555 | AryanPadarthi | Knapsack (NOI18_knapsack) | C++11 | 1064 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.
// Source: https://usaco.guide/general/io
#include <bits/stdc++.h>
using namespace std;
int main() {
int w;
int n;
int mval=0;
cin >> w >> n;
vector<long long> points(n);
vector<int> weight(n);
vector<int> count(n);
for (int i = 0; i < n; i++){
cin >> points[i] >> weight[i] >> count[i];
}
vector<long long> dp(w+1,0);
//dp[0]=1;
for (int i = 0; i < n; i++){
for (int j = 0; j < count[i]; j++){
for (int k = dp.size()-1; k > -1; k--){
if (dp[k] > 0){
if (k+weight[i]<dp.size()){
dp[k+weight[i]] = max(dp[k+weight[i]],dp[k]+points[i]);
}
}
}
if (j==0){
dp[weight[i]] = max(dp[weight[i]],points[i]);
}
}
}
for (int i = 0; i < dp.size(); i++){
if (dp[i]>mval){
mval = dp[i];
}
}
cout << mval;
}
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... |