# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1082902 | timmyli3481 | Knapsack (NOI18_knapsack) | C++14 | 1047 ms | 15880 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;
int s, n, cnt;
long long v[100001*30], w[100001*30];
long long dp[2001];
int main(){
scanf("%d%d", &s, &n);
for(int i=1; i<=n; i++){
// scanf("%lld%lld%lld", &v[i], &w[i], &k[i]);
long long vi, wi, ki;
scanf("%lld%lld%lld", &vi, &wi, &ki);
int t = 1;
while (ki>=t) {
v[++cnt]=vi*t;
w[cnt]=wi*t;
ki-=t;
t*=2;
}
if(ki>0) {
v[++cnt]=vi*ki;
w[cnt]=wi*ki;
}
}
for(int i=1; i<=cnt; i++){
for(int j=s; j>=w[i]; j--){
dp[j]=max(dp[j], dp[j-w[i]]+v[i]);
}
}
printf("%lld", dp[s]);
}
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... |