# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
484008 | T0p_ | Knapsack (NOI18_knapsack) | C++14 | 1084 ms | 1304 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;
long long dp[2][2005];
int main()
{
int s, n;
scanf(" %d %d",&s,&n);
for(int i=1 ; i<=n ; i++)
{
int w, k;
long long v;
scanf(" %lld %d %d",&v,&w,&k);
for(int j=1 ; j<=s ; j++)
{
dp[i%2][j] = max(dp[i%2][j-1], dp[(i-1)%2][j]);
for(long long t=1 ; t<=k && j-w*t>=0 ; t++) dp[i%2][j] = max(dp[i%2][j], dp[(i-1)%2][j-w*t] + v*t);
}
}
printf("%lld\n",dp[n%2][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... |