• 문제 링크
https://www.acmicpc.net/problem/6032
• 풀이 코드
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));
StringBuilder sb = new StringBuilder();
Pair[] arr = new Pair[read()];
for (int i = 0; i < arr.length; i++) arr[i] = new Pair(i, read(), read());
Arrays.sort(arr);
int sum = 0;
for (int i = 0; i < 3; sum += arr[i++].p) sb.append(arr[i].i + 1).append("\n");
sb.insert(0, sum + "\n");
bw.write(sb.toString());
bw.flush();
}
private static class Pair implements Comparable<Pair> {
int i, p;
double r;
Pair(int i, int j, int p) {
this.i = i;
this.r = (double) j / p;
this.p = p;
}
@Override
public int compareTo(Pair o) {
return Double.compare(o.r, this.r);
}
}
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' 카테고리의 다른 글
[백준] 4131 Modulo Solitaire - Graph Theory / Java (0) | 2024.07.16 |
---|---|
[백준] 30082 Atvirutės - Graph Theory / Java (0) | 2024.07.15 |
[백준] 27674 A+B - Greedy / Java (0) | 2024.07.13 |
[백준] 16533 Mount Marathon - Greedy / Java (0) | 2024.07.12 |
[백준] 21194 Meditation - Greedy / Java (0) | 2024.07.11 |
댓글