SHARE
TWEET

Untitled

lalalalalalalaalalla Jun 24th, 2019 59 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.     vi mask(p, 0);
  38.     i(p) {
  39.         mask[0]++;
  40.         int ind = 0;
  41.         while (mask[ind] == 2) {
  42.             mask[ind] = 0;
  43.             ind++;
  44.             mask[ind]++;
  45.         }
  46.         int b = 0, c = 0;
  47.         j(p) {
  48.             if (mask[j]) {
  49.                 b += a[j];
  50.             } else {
  51.                 c += a[j];
  52.             }
  53.         }
  54.         if (abs(b - c) < d) {
  55.             d = abs(b - c);
  56.         }
  57.     }
  58.     cout << d;
  59. }
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