[SWEA] 성수의 프로그래밍 강좌 시청

문제 보러가기

제한사항

정답과의 절대오차 혹은 상대 오차가 10-6이하이면 정답으로 인정된다.

첫번째 생각

수준이 낮은 강좌를 늦게 시청한다면 실력이 낮아질 수 있으므로, 정렬 후 작은 강좌부터 시청하게 한다.

Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import java.util.Arrays;
import java.util.Scanner;

public class Solution {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int T = sc.nextInt();
		
		for(int tc=1; tc<=T; tc++) {
			int N = sc.nextInt();
			int K = sc.nextInt(); // K개의 강좌를 보겠다.
			int[] M = new int[N]; 
			for(int i=0; i<N; i++) {
				M[i] = sc.nextInt(); // 강좌의 수준
			}
			Arrays.sort(M);
			double grade = 0;
			int start = (N-K) < 0 ? 0 : N-K;
			for(int i=start; i<start+K; i++) {
				grade = (grade+M[i])/2.000000;
			}

			System.out.printf("#%d %.6f\n",tc,grade);
		}
	}
}