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 <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int n,m,a[105],c[105], dp[105][10005];
int f(int x, int cost){
if(x == 0) return 0;
if(~dp[x][cost]) return dp[x][cost];
int ret = f(x-1,cost);
if(cost >= c[x-1]){
ret = max(ret,f(x-1,cost - c[x-1]) + a[x-1]);
}
return dp[x][cost] = ret;
}
int main(){
memset(dp,-1,sizeof(dp));
scanf("%d %d",&n,&m);
for (int i=0; i<n; i++) {
scanf("%d",&a[i]);
}
for (int i=0; i<n; i++) {
scanf("%d",&c[i]);
}
int s = 0, e = 10000;
while (s != e) {
int mid = (s+e)/2;
if(f(n,mid) >= m) e = mid;
else s = mid+1;
}
printf("%d",s);
}
# | 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... |