From 9ef62cf423526789e0170ff6cbb1b4eaecead3b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AF=BC=EC=A7=84?= Date: Tue, 25 Nov 2025 16:09:19 +0900 Subject: [PATCH] =?UTF-8?q?[20251125]=20BOJ=20/=20G1=20/=20=EA=B3=B5?= =?UTF-8?q?=ED=8F=89=ED=95=98=EA=B2=8C=20=ED=8C=80=20=EB=82=98=EB=88=84?= =?UTF-8?q?=EA=B8=B0=20/=20=EA=B9=80=EB=AF=BC=EC=A7=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...0 \353\202\230\353\210\204\352\270\260.md" | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 "zinnnn37/202511/25 BOJ G1 \352\263\265\355\217\211\355\225\230\352\262\214 \355\214\200 \353\202\230\353\210\204\352\270\260.md" diff --git "a/zinnnn37/202511/25 BOJ G1 \352\263\265\355\217\211\355\225\230\352\262\214 \355\214\200 \353\202\230\353\210\204\352\270\260.md" "b/zinnnn37/202511/25 BOJ G1 \352\263\265\355\217\211\355\225\230\352\262\214 \355\214\200 \353\202\230\353\210\204\352\270\260.md" new file mode 100644 index 00000000..544def8e --- /dev/null +++ "b/zinnnn37/202511/25 BOJ G1 \352\263\265\355\217\211\355\225\230\352\262\214 \355\214\200 \353\202\230\353\210\204\352\270\260.md" @@ -0,0 +1,62 @@ +```java +import java.io.*; + +public class BJ_4384_공평하게_팀_나누기 { + + private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + private static final BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + + private static int N, sum; + private static int[] weight; + private static boolean[][] dp; + + public static void main(String[] args) throws IOException { + init(); + sol(); + } + + private static void init() throws IOException { + N = Integer.parseInt(br.readLine()); + sum = 0; + + weight = new int[N]; + for (int i = 0; i < N; i++) { + weight[i] = Integer.parseInt(br.readLine()); + sum += weight[i]; + } + + dp = new boolean[N / 2 + 1][sum + 1]; + dp[0][0] = true; + } + + private static void sol() throws IOException { + // 각 사람에 대해 + for (int k = 0; k < N; k++) { + for (int i = N / 2; i > 0; i--) { + for (int j = sum; j >= weight[k]; j--) { + if (dp[i - 1][j - weight[k]]) { + dp[i][j] = true; + } + } + } + } + + int minDiff = Integer.MAX_VALUE; + int ans = 0; + for (int j = 0; j <= sum; j++) { + if (dp[N / 2][j]) { + int diff = Math.abs(sum - j - j); + if (minDiff > diff) { + minDiff = diff; + ans = j; + } + } + } + bw.write(Math.min(ans, sum - ans) + " " + Math.max(ans, sum - ans)); + bw.flush(); + bw.close(); + br.close(); + } + +} +``` \ No newline at end of file