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 N, M, m[100] = { 0 }, c[100] = { 0 };
int maxmem[100][10001] = { 0 };
int main(){
int totalc = 0, minc;
scanf("%d %d", &N, &M);
for (int i = 0; i < N; ++i){
scanf("%d", &m[i]);
}
for (int i = 0; i < N; ++i){
scanf("%d", &c[i]);
totalc += c[i];
}
maxmem[0][c[0]] = m[0];
for (int i = 1; i < N; ++i){
for (int cost = 0; cost <= totalc; ++cost){
int used=0, unused;
if (cost>c[i] && maxmem[i - 1][cost - c[i]]){
used = maxmem[i - 1][cost - c[i]] + m[i];
}
else if (cost == c[i]){
if(used < m[i])
used=m[i];
}
unused = maxmem[i-1][cost];
maxmem[i][cost] = (used > unused ? used : unused);
}
}
for (minc = 0; minc <= totalc; ++minc){
if (maxmem[N - 1][minc] >= M) break;
}
printf("%d\n", minc);
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... |