본문 바로가기
Problem Solving/Baekjoon

[백준] 21146 Rating Problems - Greedy / Java

by graycode 2024. 4. 13.

 문제 링크

 

21146번: Rating Problems

Output two space-separated floating point numbers on a single line, which are the minimum and maximum overall rating the problem could achieve after the remaining judges rate the problem, minimum first. These values must be accurate to an absolute or relat

www.acmicpc.net

 

 풀이 코드

import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));

        int n = read(), k = read();

        float sum = 0;
        for (int i = 0; i < k; i++) sum += read();

        bw.write((sum + -3 * (n - k)) / n + " " + (sum + 3 * (n - k)) / n);
        bw.flush();
    }

    private static int read() throws IOException {
        int c, n = System.in.read() & 15;
        boolean flag = n == 13;

        if (flag) n = System.in.read() & 15;
        while ((c = System.in.read()) > 32) n = (n << 3) + (n << 1) + (c & 15);

        return flag ? ~n + 1 : n;
    }

}

댓글