#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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
4996 KB |
Output is correct |
2 |
Correct |
0 ms |
4996 KB |
Output is correct |
3 |
Correct |
0 ms |
4996 KB |
Output is correct |
4 |
Correct |
0 ms |
4996 KB |
Output is correct |
5 |
Correct |
0 ms |
4996 KB |
Output is correct |
6 |
Correct |
0 ms |
4996 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
4996 KB |
Output is correct |
2 |
Correct |
0 ms |
4996 KB |
Output is correct |
3 |
Correct |
0 ms |
4996 KB |
Output is correct |
4 |
Correct |
0 ms |
4996 KB |
Output is correct |
5 |
Correct |
0 ms |
4996 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
4996 KB |
Output is correct |
2 |
Correct |
0 ms |
4996 KB |
Output is correct |
3 |
Correct |
0 ms |
4996 KB |
Output is correct |
4 |
Correct |
0 ms |
4996 KB |
Output is correct |
5 |
Correct |
0 ms |
4996 KB |
Output is correct |
6 |
Correct |
0 ms |
4996 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
4996 KB |
Output is correct |
2 |
Correct |
0 ms |
4996 KB |
Output is correct |
3 |
Correct |
0 ms |
4996 KB |
Output is correct |
4 |
Correct |
0 ms |
4996 KB |
Output is correct |
5 |
Correct |
0 ms |
4996 KB |
Output is correct |
6 |
Correct |
0 ms |
4996 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
4996 KB |
Output is correct |
2 |
Correct |
0 ms |
4996 KB |
Output is correct |
3 |
Correct |
0 ms |
4996 KB |
Output is correct |
4 |
Correct |
0 ms |
4996 KB |
Output is correct |
5 |
Correct |
0 ms |
4996 KB |
Output is correct |
6 |
Correct |
0 ms |
4996 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
4996 KB |
Output is correct |
2 |
Correct |
0 ms |
4996 KB |
Output is correct |
3 |
Correct |
0 ms |
4996 KB |
Output is correct |
4 |
Correct |
0 ms |
4996 KB |
Output is correct |
5 |
Correct |
0 ms |
4996 KB |
Output is correct |
6 |
Correct |
0 ms |
4996 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
4996 KB |
Output is correct |
2 |
Correct |
0 ms |
4996 KB |
Output is correct |
3 |
Correct |
4 ms |
4996 KB |
Output is correct |
4 |
Correct |
0 ms |
4996 KB |
Output is correct |