summaryrefslogtreecommitdiff
path: root/introductory_problems/apple_division.cpp
diff options
context:
space:
mode:
authorJack Sangdahl <[email protected]>2025-02-19 11:48:40 -0700
committerJack Sangdahl <[email protected]>2025-02-20 12:29:15 -0700
commit1bd17a77301438997ccc4e3eaf7ebe04474a5767 (patch)
treedb282449741ba5411368412bca03cd28786f02b8 /introductory_problems/apple_division.cpp
parentdcef6fef864949bcde09907c120180733e5d37bc (diff)
downloadcses-1bd17a77301438997ccc4e3eaf7ebe04474a5767.tar.gz
cses-1bd17a77301438997ccc4e3eaf7ebe04474a5767.zip
1623. apple division
Diffstat (limited to 'introductory_problems/apple_division.cpp')
-rw-r--r--introductory_problems/apple_division.cpp23
1 files changed, 23 insertions, 0 deletions
diff --git a/introductory_problems/apple_division.cpp b/introductory_problems/apple_division.cpp
new file mode 100644
index 0000000..11a0450
--- /dev/null
+++ b/introductory_problems/apple_division.cpp
@@ -0,0 +1,23 @@
+// 1623. Apple Division
+#include <bits/stdc++.h>
+using namespace std;
+
+int main() {
+ const long long max = INT_MAX;
+ static int n, p[20];
+ long long a, b, best = max;
+ scanf("%d", &n);
+ for (int i = 0; i < n; i++)
+ scanf("%d", &p[i]);
+ for (int i = 0; i < (1 << n); i++) {
+ a = b = 0;
+ for (int j = 0; j < n; j++) {
+ if (i & (1 << j))
+ a += p[j];
+ else
+ b += p[j];
+ }
+ best = min(best, abs(a - b));
+ }
+ printf("%lld\n", best);
+}