We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 39acb02 commit 2b679f3Copy full SHA for 2b679f3
Introductory Problems/AppleDivision.cpp
@@ -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