Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- long long int n,sum=0,res,a[30],x,p1w,p2w;
- void pile(long long int depth,long long int p1w)
- {
- if(depth>n)
- {
- p2w=abs(sum-p1w);
- res=min(res,abs(p1w-p2w));
- return;
- }
- pile(depth+1,p1w);
- pile(depth+1,p1w+a[depth]);
- return;
- }
- int main()
- {
- long long int i;
- cin>>n;
- for(i=0; i<n; i++)
- {
- cin>>a[i];
- sum+=a[i];
- }
- res=10000000;
- pile(0,0);
- cout<<res<<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement