# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
427933 | Amylopectin | Knapsack (NOI18_knapsack) | C++14 | 679 ms | 2500 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 <stdio.h>
using namespace std;
const int mxn = 1e5 + 10;
long long ta[mxn] = {},nru[mxn] = {},chc[mxn] = {};
long long fima(long long l,long long r)
{
if(l > r)
return l;
return r;
}
int main()
{
long long i,j,n,m,cva,cwe,cco,cma = 0,k;
scanf("%lld %lld",&m,&n);
for(i=0; i<n; i++)
{
scanf("%lld %lld %lld",&cva,&cwe,&cco);
for(j=0; j<cwe; j++)
{
nru[j] = ta[j];
}
for(j=cwe; j<=m; j++)
{
if(chc[j-cwe] == cco)
{
// nru[j] = fima(ta[j-(cco * cwe)] + (cco * cva), ta[j]);
nru[j] = ta[j];
for(k=1; k<=cco; k++)
{
if(ta[j-(k*cwe)] + (k*cva) > nru[j])
{
nru[j] = ta[j-(k*cwe)] + (k*cva);
chc[j] = k;
}
}
// if(ta[j-(cco * cwe)] + (cco * cva) > ta[j])
// {
// nru[j] = ta[j-(cco * cwe)] + (cco * cva);
// chc[j] = cco;
// }
// else
// {
// nru[j] = ta[j];
// }
// chc[j] = cco;
}
else
{
// nru[j] = fima(, ta[j]);
if(nru[j-cwe] + cva > ta[j])
{
// if(j-cwe < cwe)
// {
// nru[j] = ta[j-cwe] + cva;
// }
// else
// {
nru[j] = nru[j-cwe] + cva;
// }
chc[j] = chc[j-cwe] + 1;
}
else
{
nru[j] = ta[j];
}
}
}
for(j=cwe; j<=m; j++)
{
chc[j] = 0;
ta[j] = fima(nru[j],ta[j]);
nru[j] = 0;
}
}
for(i=0; i<=m; i++)
{
cma = fima(cma,ta[i]);
}
printf("%lld\n",cma);
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... |