# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
531099 | mihh | Knapsack (NOI18_knapsack) | C++17 | 425 ms | 268 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>
#define db(x) cerr << #x <<":"<<x<<" "
using namespace std;
const int INF=1e9, MOD=1e9+7;
// const int N=1e5+2;
int main(){
#ifndef ONLINE_JUDGE
freopen("frog.in", "r", stdin);
freopen("frog.out", "w", stdout);
#endif
int n, kg; cin>>kg>>n;
vector<vector<int>> bst(n+1,vector<int>(kg+1,0));
for(int i=1;i<=n;++i){
int v,w,k;
cin>>v>>w>>k;
for(int s=0;s<=kg;++s){
for(int nr=0; nr<=k and s-nr*w>=0; ++nr)
bst[i][s]=max(bst[i-1][s-nr*w]+nr*v, bst[i][s]);
}
}
int ans=0;
for(int s=1;s<=kg;++s)
ans=max(ans, bst[n][s]);
cout<<ans;
}
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... |