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 <stdio.h>
int mem[100];
int cost[100];
int d[100][10001];
int main()
{
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
int n, m;
int i, j;
int maxcost=0;
scanf("%d %d", &n, &m);
for(i=0; i<n; i++)
{
scanf(" %d", &mem[i]);
}
for(i=0; i<n; i++)
{
scanf(" %d", &cost[i]);
maxcost+=cost[i];
}
for(i=0; i<n; i++)
for(j=0; j<=maxcost; j++)
d[i][j]=-1;
d[0][0]=0;
d[0][cost[0]]=mem[0];
for(i=1; i<n; i++)
{
for(j=0; j<=maxcost; j++)
d[i][j]=d[i-1][j];
for(j=cost[i]; j<=maxcost; j++)
{
if(d[i-1][j-cost[i]]!=-1 && d[i-1][j]<d[i-1][j-cost[i]]+mem[i])
{
d[i][j]=d[i-1][j-cost[i]]+mem[i];
}
}
}
for(j=0; j<=maxcost; j++)
{
if(d[n-1][j]>=m)
{
printf("%d", j);
break;
}
}
return 0;
}
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |