• 문제 링크
https://www.acmicpc.net/problem/27100
• 풀이 코드
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.Arrays;
public class Main {
public static void main(String[] args) throws IOException {
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
int s = read(), e = read();
int[] arr = new int[s];
for (int i = 0; i < s; i++) arr[i] = read();
int[] dist = new int[20001];
Arrays.fill(dist, 20001);
dist[0] = 0;
for (int i : arr)
for (int j = i; j < dist.length; j++) dist[j] = Math.min(dist[j], dist[j - i] + 1);
int max = 0, cnt = 1;
for (int i = 1; i < dist.length; i++) {
if (dist[i] > e) {
max = Math.max(max, i - cnt);
cnt = i + 1;
}
}
bw.write(String.valueOf(max));
bw.flush();
}
private static int read() throws IOException {
int c, n = System.in.read() & 15;
while ((c = System.in.read()) > 32) n = (n << 3) + (n << 1) + (c & 15);
return n;
}
}
'Problem Solving > Baekjoon' 카테고리의 다른 글
[백준] 9700 RAINFOREST CANOPY - Graph Theory / Java (0) | 2024.05.06 |
---|---|
[백준] 10204 Neighborhoods in Graphs - Graph Theory / Java (0) | 2024.05.05 |
[백준] 15081 Is Everybody Appy? - Data Structure / Java (0) | 2024.05.03 |
[백준] 10689 Hamza - Data Structure / Java (0) | 2024.05.02 |
[백준] 5263 samba - Data Structure / Java (0) | 2024.05.01 |
댓글