From 020e8ada69d9d65c7f768c85ed4151e30e641569 Mon Sep 17 00:00:00 2001 From: lkhyun <102892446+lkhyun@users.noreply.github.com> Date: Sun, 8 Jun 2025 22:58:51 +0900 Subject: [PATCH] =?UTF-8?q?[20250608]=20BOJ=20/=20G4=20/=20=ED=98=B8?= =?UTF-8?q?=ED=85=94=20/=20=EC=9D=B4=EA=B0=95=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../08 BOJ G4 \355\230\270\355\205\224.md" | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 "lkhyun/202506/08 BOJ G4 \355\230\270\355\205\224.md" diff --git "a/lkhyun/202506/08 BOJ G4 \355\230\270\355\205\224.md" "b/lkhyun/202506/08 BOJ G4 \355\230\270\355\205\224.md" new file mode 100644 index 00000000..c3ad4477 --- /dev/null +++ "b/lkhyun/202506/08 BOJ G4 \355\230\270\355\205\224.md" @@ -0,0 +1,48 @@ +```java +import java.io.*; +import java.util.*; + +public class Main { + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + static StringTokenizer st; + static int C,N; + static int[] cost; + static int[] client; + static int[] dp; + + public static void main(String[] args) throws IOException { + st = new StringTokenizer(br.readLine()); + C = Integer.parseInt(st.nextToken()); + N = Integer.parseInt(st.nextToken()); + + cost = new int[N]; + client = new int[N]; + dp = new int[1200]; //인덱스만큼의 인원을 홍보할때 그 비용 + Arrays.fill(dp,Integer.MAX_VALUE); + dp[0] = 0; + + for (int i = 0; i < N; i++) { + st = new StringTokenizer(br.readLine()); + cost[i] = Integer.parseInt(st.nextToken()); //홍보 비용 + client[i] = Integer.parseInt(st.nextToken()); //홍보했을때 얻는 고객 수 + } + + for (int i = 0; i < N; i++) {//모든 도시에 대해 + for (int j = client[i]; j < dp.length; j++) { + if(dp[j-client[i]] != Integer.MAX_VALUE) { + dp[j] = Math.min(dp[j], dp[j-client[i]] + cost[i]); + } + } + } + int min = Integer.MAX_VALUE; + for (int i = C; i < dp.length ; i++) { + min = Math.min(min, dp[i]); + } + bw.write(min + ""); + bw.close(); + } +} + + +```