• 문제 링크
https://www.acmicpc.net/problem/17224
• 풀이 코드
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));
Pair[] arr = new Pair[read()];
int l = read(), k = read();
for (int i = 0; i < arr.length; i++) arr[i] = new Pair(read(), read());
Arrays.sort(arr);
int sum = 0;
for (Pair p : arr) {
if (k-- == 0) break;
if (p.b <= l) sum += 140;
else if (p.a <= l) sum += 100;
else k++;
}
bw.write(String.valueOf(sum));
bw.flush();
}
private static class Pair implements Comparable<Pair> {
int a, b;
Pair(int a, int b) {
this.a = a;
this.b = b;
}
@Override
public int compareTo(Pair o) {
return this.b != o.b ? this.b - o.b : this.a - o.a;
}
}
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' 카테고리의 다른 글
| [백준] 14623 감정이입 - Implementation / Java (0) | 2025.10.29 |
|---|---|
| [백준] 15904 UCPC는 무엇의 약자일까? - Greedy / Java (0) | 2025.10.28 |
| [백준] 2720 세탁소 사장 동혁 - Greedy / Java (0) | 2025.10.26 |
| [백준] 31448 Ascending hike - Greedy / Java (0) | 2025.10.25 |
| [백준] 30700 KOREA 문자열 만들기 - Greedy / Java (0) | 2025.10.24 |
댓글