From b2460177fab271eff9daa8ce3a509bb70bd4c930 Mon Sep 17 00:00:00 2001 From: oncsr Date: Wed, 12 Feb 2025 10:26:30 +0900 Subject: [PATCH] =?UTF-8?q?[20250212]=20BOJ=20/=20G5=20/=20=EC=B0=BD?= =?UTF-8?q?=EC=98=81=EC=9D=B4=EC=99=80=20=EC=BB=A4=ED=94=BC=20/=20?= =?UTF-8?q?=EA=B6=8C=ED=98=81=EC=A4=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4\354\231\200 \354\273\244\355\224\274.md" | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 "khj20006/202502/12 BOJ G5 \354\260\275\354\230\201\354\235\264\354\231\200 \354\273\244\355\224\274.md" diff --git "a/khj20006/202502/12 BOJ G5 \354\260\275\354\230\201\354\235\264\354\231\200 \354\273\244\355\224\274.md" "b/khj20006/202502/12 BOJ G5 \354\260\275\354\230\201\354\235\264\354\231\200 \354\273\244\355\224\274.md" new file mode 100644 index 00000000..750666ff --- /dev/null +++ "b/khj20006/202502/12 BOJ G5 \354\260\275\354\230\201\354\235\264\354\231\200 \354\273\244\355\224\274.md" @@ -0,0 +1,56 @@ +```java + +import java.util.*; +import java.io.*; + +class Main { + + // IO field + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + static StringTokenizer st; + + static void nextLine() throws Exception {st = new StringTokenizer(br.readLine());} + static int nextInt() {return Integer.parseInt(st.nextToken());} + static long nextLong() {return Long.parseLong(st.nextToken());} + static void bwEnd() throws Exception {bw.flush();bw.close();} + + // Additional field + static int[] dp; + static int N, K; + + public static void main(String[] args) throws Exception { + + //ready(); + solve(); + + bwEnd(); + } + + static void ready() throws Exception{ + + + } + + static void solve() throws Exception{ + + nextLine(); + N = nextInt(); + K = nextInt(); + dp = new int[100001]; + Arrays.fill(dp, Integer.MAX_VALUE-1); + dp[0] = 0; + nextLine(); + while(N-- > 0) { + int now = nextInt(); + for(int j=100000;j>now;j--) if(dp[j-now] != 0) dp[j] = Math.min(dp[j-now]+1, dp[j]); + dp[now] = 1; + } + bw.write((dp[K] == Integer.MAX_VALUE-1 ? -1 : dp[K]) + "\n"); + + + } + +} + +```