Created
April 1, 2024 23:03
-
-
Save dimahmz/66cd36938371455ecfeba4eee71be9a3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #include <vector> | |
| #include <algorithm> | |
| #include <cmath> | |
| #include <numeric> | |
| #include <cstddef> | |
| using namespace std; | |
| #define ll long long | |
| void solve(vector<int> &numbers, size_t i, ll sum, vector<ll> &groups) | |
| { | |
| if (i == numbers.size()) | |
| { | |
| groups.push_back(sum); | |
| return; | |
| } | |
| solve(numbers, i + 1, sum + numbers[i], groups); | |
| solve(numbers, i + 1, sum, groups); | |
| } | |
| int main() | |
| { | |
| int n; | |
| cin >> n; | |
| vector<int> ints; | |
| for (int i = 0; i < n; i++) | |
| { | |
| int temp; | |
| cin >> temp; | |
| ints.push_back(temp); | |
| } | |
| vector<ll> groups; | |
| solve(ints, 0, 0, groups); | |
| sort(groups.rbegin(), groups.rend()); | |
| int center = groups.size() / 2; | |
| if (groups.size() % 2 != 0) | |
| { | |
| cout << abs(groups[0] - 2 * groups[center]); | |
| return 0; | |
| } | |
| int small = min(abs(groups[0] - 2 * groups[center]), abs(groups[0] - 2 * groups[center - 1])); | |
| cout << small; | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment