fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define all(x) x.begin(), x.end()
  4. #define pb push_back
  5. typedef long long ll ;
  6. set < ll > st ;
  7. void make_sums (vector < ll > &a , ll index , ll sum , ll maxi , ll total ) {
  8. if (index == maxi ) {
  9. st.insert(abs(total - 2 * sum) ) ;
  10. return ;
  11. }
  12. make_sums (a , index+1 , sum+a[index] , maxi , total );
  13. make_sums (a , index+1 , sum , maxi, total );
  14.  
  15. }
  16.  
  17.  
  18. void solve() {
  19. ll n ;
  20.  
  21. cin >> n ;
  22. vector<ll> a(n) ;
  23. ll total = 0 ;
  24. for (ll i = 0 ; i < n ; i++) {
  25. cin >> a[i] ;
  26. total += a[i] ;
  27. }
  28. make_sums (a, 0, 0, n , total) ;
  29.  
  30. cout <<*st.begin()<< endl ;
  31.  
  32.  
  33.  
  34.  
  35.  
  36. }
  37. int main() {
  38. ll t ;
  39.  
  40. t=1;
  41. ///cin >> t ;
  42. while (t-- ) {
  43. solve();
  44.  
  45.  
  46. }
  47.  
  48.  
  49.  
  50. return 0;
  51. }
Success #stdin #stdout 0s 5276KB
stdin
Standard input is empty
stdout
0