From ccdc28600effd176ac47bb1709ed3757f535da80 Mon Sep 17 00:00:00 2001 From: lkhyun <102892446+lkhyun@users.noreply.github.com> Date: Sun, 20 Jul 2025 14:27:53 +0900 Subject: [PATCH] =?UTF-8?q?[20250720]=20BOJ=20/=20G4=20/=20=EB=8B=A4?= =?UTF-8?q?=EC=9D=B4=EC=96=B4=ED=8A=B8=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 --- ...44\354\235\264\354\226\264\355\212\270.md" | 75 +++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 "lkhyun/202507/20 BOJ G4 \353\213\244\354\235\264\354\226\264\355\212\270.md" diff --git "a/lkhyun/202507/20 BOJ G4 \353\213\244\354\235\264\354\226\264\355\212\270.md" "b/lkhyun/202507/20 BOJ G4 \353\213\244\354\235\264\354\226\264\355\212\270.md" new file mode 100644 index 00000000..41f089bc --- /dev/null +++ "b/lkhyun/202507/20 BOJ G4 \353\213\244\354\235\264\354\226\264\355\212\270.md" @@ -0,0 +1,75 @@ +```java +import java.util.*; +import java.io.*; + +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 N; + static int[] minimumCond = new int[4]; + static int[][] food; + static int[] cost; + + public static void main(String[] args) throws Exception { + N = Integer.parseInt(br.readLine()); + + st = new StringTokenizer(br.readLine()); + for (int i = 0; i < 4; i++) { + minimumCond[i] = Integer.parseInt(st.nextToken()); + } + + food = new int[N][5]; + for (int i = 0; i < N; i++) { + st = new StringTokenizer(br.readLine()); + food[i][0] = Integer.parseInt(st.nextToken()); //단백질 + food[i][1] = Integer.parseInt(st.nextToken()); //지방 + food[i][2] = Integer.parseInt(st.nextToken()); //탄수화물 + food[i][3] = Integer.parseInt(st.nextToken()); //비타민 + food[i][4] = Integer.parseInt(st.nextToken()); //가격 + } + int ans = Integer.MAX_VALUE; + String state = ""; + cost = new int[1< sum[4]){ + ans = sum[4]; + state = stateToStr(i); + + }else if(ans == sum[4]){ + String temp = stateToStr(i); + if(state.compareTo(temp) > 0){ + state = temp; + } + } + + } + if(ans == Integer.MAX_VALUE){ + bw.write("-1\n"); + }else{ + bw.write(ans+"\n"+state); + } + bw.close(); + } + static String stateToStr(int state){ + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < N; i++) { + if((state & (1<