# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
713614 | NNerver | Knapsack (NOI18_knapsack) | C++14 | 1080 ms | 2712 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;
const int MAXN = 1e5 + 10;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9+7;
int N,S;
int v[MAXN],w[MAXN],k[MAXN];
int dp[MAXN];
void update(int V,int W){
for(int i=S;i>=W;i--){
dp[i]=max(dp[i],dp[i-W]+V);
}
}
int main(){
scanf("%d%d",&S,&N);
for(int i=1;i<=N;i++){
scanf("%d%d%d",&v[i],&w[i],&k[i]);
}
for(int i=1;i<=N;i++){
int K=min(k[i],S/w[i]);
int cnt=1;
for(;cnt<=K;cnt*=2){
update(v[i]*cnt,w[i]*cnt);
K-=cnt;
}
update(v[i]*K,w[i]*K);
}
printf("%d\n",dp[S]);
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... |