Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <string>
- #include <iomanip>
- #include <queue>
- #include <cmath>
- #include <algorithm>
- #include <tuple>
- #include <iomanip>
- #include <stdio.h>
- #include <numeric>
- #include <map>
- #define ll long long
- #define i(n) for (int i = 0; i < n; i++)
- #define j(n) for (int j = 0; j < n; j++)
- #define vi vector<int>
- #define ull unsigned long long
- #define vvi vector<vector<int>>
- #define all(a) a.begin(), a.end()
- #define pii pair<int, int>
- #define pb push_back
- using namespace std;
- int main()
- {
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- int n;
- cin >> n;
- vi a(n);
- i(n) cin >> a[i];
- ll p = pow(2, n);
- int d = 100000;
- vi mask(p, 0);
- i(p) {
- mask[0]++;
- int ind = 0;
- while (mask[ind] == 2) {
- mask[ind] = 0;
- ind++;
- mask[ind]++;
- }
- int b = 0, c = 0;
- j(p) {
- if (mask[j]) {
- b += a[j];
- } else {
- c += a[j];
- }
- }
- if (abs(b - c) < d) {
- d = abs(b - c);
- }
- }
- cout << d;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement