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