Created
December 4, 2013 11:34
-
-
Save kimitoboku/7786171 to your computer and use it in GitHub Desktop.
駄目な解答
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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