Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<math.h>
- int main()
- {
- long long int N,n,i,j,k,l,a[30],t,max;
- while(scanf("%lld %lld",&N,&n)!=EOF){
- for(i=0;i<n;i++){
- scanf("%lld",&a[i]);
- }
- k=pow(2,n);
- max=0;
- for(i=0;i<k;i++){
- t=0;
- for(j=0;j<n;j++){
- if(i&(1<<j))
- t=t+a[j];
- }
- if(t>max && t<=N){
- max=t;
- l=i;
- }
- }
- for(j=0;j<n;j++){
- if(l&(1<<j))
- printf("%lld ",a[j]);
- }
- printf("sum:%lld\n",max);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement