• 문제 링크
https://www.acmicpc.net/problem/31307
• 풀이 코드
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[] arr = new int[read()];
int l = read() * 5;
for (int i = 0; i < arr.length; i++) arr[i] = read();
Arrays.sort(arr);
int cnt = 0;
for (int i : arr) {
if (l - i < 0) break;
l -= i;
cnt++;
}
bw.write(String.valueOf(cnt));
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' 카테고리의 다른 글
| [백준] 3211 kino - Greedy / Java (0) | 2025.12.20 |
|---|---|
| [백준] 7274 Liftas - Greedy / Java (0) | 2025.12.19 |
| [백준] 33572 자세히 보아야 예쁘다 - Greedy / Java (0) | 2025.12.17 |
| [백준] 13638 Coral Perfeito - Greedy / Java (0) | 2025.12.16 |
| [백준] 4435 중간계 전쟁 - Implementation / Java (0) | 2025.12.15 |
댓글