SHARE
TWEET

Untitled

lalalalalalalaalalla Jun 24th, 2019 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <vector>
  3. #include <string>
  4. #include <iomanip>
  5. #include <queue>
  6. #include <cmath>
  7. #include <algorithm>
  8. #include <tuple>
  9. #include <iomanip>
  10. #include <stdio.h>
  11. #include <numeric>
  12. #include <map>
  13.  
  14. #define ll long long
  15. #define i(n) for (int i = 0; i < n; i++)
  16. #define j(n) for (int j = 0; j < n; j++)
  17. #define vi vector<int>
  18. #define ull unsigned long long
  19. #define vvi vector<vector<int>>
  20. #define all(a) a.begin(), a.end()
  21. #define pii pair<int, int>
  22. #define pb push_back
  23.  
  24. using namespace std;
  25.  
  26. int main()
  27. {
  28.     ios_base::sync_with_stdio(0);
  29.     cin.tie(0);
  30.     cout.tie(0);
  31.     int n;
  32.     cin >> n;
  33.     vi a(n);
  34.     i(n) cin >> a[i];
  35.     ll p = pow(2, n);
  36.     int d = 100000;
  37.     i(p) {
  38.         vi mask(p, 0);
  39.         j(i) {
  40.             mask[0]++;
  41.             int ind = 0;
  42.             while (mask[ind] == 2) {
  43.                 mask[ind] = 0;
  44.                 ind++;
  45.                 mask[ind]++;
  46.             }
  47.         }
  48.         int b = 0, c = 0;
  49.         j(p) {
  50.             if (mask[j]) {
  51.                 b += a[j];
  52.             } else {
  53.                 c += a[j];
  54.             }
  55.         }
  56.         if (abs(b - c) < d) {
  57.             d = abs(b - c);
  58.         }
  59.     }
  60.     cout << d;
  61. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top