Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
駄目な解答
#include<iostream>
using namespace std;
int p[500000];
int m[300];
int max(int a,int b){
return (a < b) ? b : a;
}
int solve(int i,int n,int sum,int lim,int r){
if(sum <= lim){
r = max(r,sum);
}
if(i==n){
return r;
}
return max(solve(i+1,n,sum+p[i],lim,r),solve(i+1,n,sum,lim,r));
}
int main(){
int n,d;
int r[300] = {0};
cin >> n >> d;
for(int i=0;i<n;i++){
cin >> p[i];
}
for(int i=0;i<d;i++){
cin >> m[i];
}
for(int i=0;i<d;i++){
r[i] = solve(0,n,0,m[i],0);
}
for(int i=0;i<d;i++){
cout << r[i] << endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment