Advertisement
elephantsarecool

timus1005

Nov 28th, 2017
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.49 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. int main()
  4. {
  5.     int n,mini=9999999;
  6.     int a[25];
  7.     cin>>n;
  8.     for (int i=0;i<n;i++)
  9.         cin>>a[i];
  10.     int z=1<<n;
  11.     cout<<z<<endl;
  12.     while (z)
  13.         {
  14.             int sum=0;
  15.             for (int i=0;i<n;i++)
  16.             {
  17.                 if (z&(1<<i)) sum+=a[i];
  18.                 else sum-=a[i];
  19.             }
  20.             if (sum>=0&&mini>sum) mini=sum;
  21.             z--;
  22.         }
  23.     cout<<mini<<endl;
  24.     return 0;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement