Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstring>
- #include <cmath>
- using namespace std;
- int arr[305];
- int main()
- {
- int n;
- cin >> n;
- for(int i = 0; i < n; i++) {
- cin >> arr[i];
- }
- int razlika = 2e9;
- for(int bitmask = 0; bitmask < (1 << n); bitmask++) {
- int sum1 = 0, sum2 = 0;
- for(int i = 0; i < n; i++) {
- if(bitmask & (1 << i)) {
- sum1 += arr[i];
- }
- else {
- sum2 += arr[i];
- }
- }
- razlika = min(razlika, abs(sum1 - sum2));
- }
- cout << razlika << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement