# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1067482 | rohanjha | Knapsack (NOI18_knapsack) | C++14 | 1026 ms | 165368 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<iostream>
#include<vector>
using namespace std;
int main(){
int s, n;
cin>>s>>n;
vector<vector<int> > items;
for(int i=0; i<n; i++){
int v, w, k;
cin>>v>>w>>k;
vector<int> item;
item.push_back(v);
item.push_back(w);
item.push_back(k);
items.push_back(item);
}
vector<vector<int> > item_list;
for(int i=0; i<n; i++){
for(int j=1; j<=items[i][2]; j++){
vector<int> item;
item.push_back(items[i][0]);
item.push_back(items[i][1]);
item_list.push_back(item);
}
}
vector<int> dp(s+1, 0);
for(int i=0; i<item_list.size(); i++){
for(int j=s; j>=item_list[i][1]; j--){
dp[j] = max(dp[j], dp[j-item_list[i][1]]+item_list[i][0]);
}
}
std::cout<<dp[s]<<endl;
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... |