Advertisement
Nusrat_Ullah

Timus 1005

Jan 29th, 2019
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.42 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5.     int g,h,t,wq[25],pile1,pile2,res;
  6.     scanf("%d",&t);
  7.     for(g=0;g<t;g++) scanf("%d",&wq[g]);
  8.     res=1e9;
  9.     for(g=0;g<(1<<t);g++){
  10.         pile1=pile2=0;
  11.         for(h=0;h<t;h++){
  12.             if(g&(1<<h)) pile1+=wq[h];
  13.             else pile2+=wq[h];
  14.         }
  15.         res=min(res,abs(pile1-pile2));
  16.     }
  17.     printf("%d\n",res);
  18.     return 0;
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement