Skip to content

Commit 2b679f3

Browse files
authored
Add files via upload
1 parent 39acb02 commit 2b679f3

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#include <bits/stdc++.h>
2+
//@ReetuRaj77
3+
#define lli long long int
4+
#define ulli unsigned long long int
5+
6+
#define all(x) (x).begin(),(x).end()
7+
8+
#define fastio ios_base::sync_with_stdio(false);cin.tie(nullptr)
9+
10+
using namespace std;
11+
12+
13+
int main() {
14+
fastio;
15+
int n;
16+
cin >> n;
17+
lli ar[n + 1];
18+
for (int i = 0; i < n; i++)
19+
cin >> ar[i];
20+
lli ans = (lli)1e18;
21+
for (int mask = 0; mask < (1 << n); mask++) {
22+
lli s1 = 0, s2 = 0;
23+
for (int j = 0; j < n; j++) {
24+
if (mask & (1 << j)) { //if the j-th bit is toggled
25+
s1 += ar[j];
26+
}
27+
else {
28+
s2 += ar[j];
29+
}
30+
}
31+
ans = min(ans, abs(s1 - s2));
32+
}
33+
cout << ans << '\n';
34+
return 0;
35+
}

0 commit comments

Comments
 (0)