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>
#include<algorithm>
using namespace std;
int D[105][10500];
int N,M,m[105],c[105];
int s;
int ans=100000000;
int input();
int solve();
int output();
int input(){
scanf("%d %d",&N,&M);
for(int i=1;i<=N;i++)scanf("%d",&m[i]);
for(int i=1;i<=N;i++){scanf("%d",&c[i]);s+=c[i];}
return 0;
}
int solve(){
for(int i=1;i<=N;i++){
for(int j=1;j<=s;j++){
if(j<c[i]){
D[i][j]=D[i-1][j];
}
else
D[i][j]=max(D[i-1][j-c[i]]+m[i],D[i-1][j]);
if(D[i][j]>=M) ans=min(ans,j);
}
}
return 0;
}
int output(){
printf("%d",ans);
return 0;
}
int main(){
input();
solve();
output();
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... |