Advertisement
Farjana_akter

Untitled

Jun 24th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. long long int n,sum=0,res,a[30],x,p1w,p2w;
  4.  
  5.  
  6. void pile(long long int depth,long long int p1w)
  7. {
  8. if(depth>n)
  9. {
  10. p2w=abs(sum-p1w);
  11. res=min(res,abs(p1w-p2w));
  12. return;
  13. }
  14. pile(depth+1,p1w);
  15. pile(depth+1,p1w+a[depth]);
  16. return;
  17. }
  18.  
  19.  
  20. int main()
  21. {
  22. long long int i;
  23. cin>>n;
  24. for(i=0; i<n; i++)
  25. {
  26. cin>>a[i];
  27. sum+=a[i];
  28. }
  29. res=10000000;
  30. pile(0,0);
  31. cout<<res<<endl;
  32. return 0;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement