-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1623.cpp
37 lines (32 loc) · 805 Bytes
/
1623.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define endl "\n"
int main()
{
ll n, i;
cin >> n;
ll arr[n];
ll total = 0, ans, temp, temp_ans;
for (i = 0; i < n; i++)
{
cin >> arr[i];
total += arr[i];
}
ans = LONG_LONG_MAX;
for(i = 0; i < (1 << n); i++)
{
temp = 0;
for(ll j = 0; j < n; j++)
{
if(i & (1 << j))
{
temp += arr[j];
}
}
temp_ans = abs((total - temp) - temp);
ans = min(ans, temp_ans);
}
cout << ans << endl;
return 0;
}