From db5ba8c79d28ace605cb0c3625b44544acbd6067 Mon Sep 17 00:00:00 2001 From: Ukj0ng <90972240+Ukj0ng@users.noreply.github.com> Date: Wed, 4 Feb 2026 12:37:32 +0900 Subject: [PATCH] =?UTF-8?q?[20260204]=20BOJ=20/=20G2=20/=20=EC=BA=94?= =?UTF-8?q?=EB=94=94=EC=BA=94=EB=94=94=20/=20=ED=95=9C=EC=A2=85=EC=9A=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...24\353\224\224\354\272\224\353\224\224.md" | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 "Ukj0ng/202602/04 BOJ G2 \354\272\224\353\224\224\354\272\224\353\224\224.md" diff --git "a/Ukj0ng/202602/04 BOJ G2 \354\272\224\353\224\224\354\272\224\353\224\224.md" "b/Ukj0ng/202602/04 BOJ G2 \354\272\224\353\224\224\354\272\224\353\224\224.md" new file mode 100644 index 00000000..12574f98 --- /dev/null +++ "b/Ukj0ng/202602/04 BOJ G2 \354\272\224\353\224\224\354\272\224\353\224\224.md" @@ -0,0 +1,51 @@ +``` +import java.io.*; +import java.util.Arrays; +import java.util.StringTokenizer; + +public class Main { + private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + private static final BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + private static final long INF = (long)Math.pow(2, 64); + private static long[] arr; + private static long sum, answer; + private static int M, N; + + public static void main(String[] args) throws IOException { + init(); + + bw.write(answer + "\n"); + bw.flush(); + bw.close(); + br.close(); + } + + private static void init() throws IOException { + StringTokenizer st = new StringTokenizer(br.readLine()); + M = Integer.parseInt(st.nextToken()); + N = Integer.parseInt(st.nextToken()); + + arr = new long[N]; + + for (int i = 0; i < N; i++) { + arr[i] = Long.parseLong(br.readLine()); + sum += arr[i]; + } + + Arrays.sort(arr); + + long temp = sum - M; + + for (int i = 0; i < N; i++) { + long n = temp / (N-i); + if (n >= arr[i]) { + temp -= arr[i]; + answer = (arr[i]*arr[i] + answer) % INF; + } else { + temp -= n; + answer = (n*n + answer) % INF; + } + } + } +} +```