-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2.java
38 lines (29 loc) · 1.28 KB
/
2.java
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
28
29
30
31
32
33
34
35
36
37
38
/*
<문제>
동빈이의 큰수의 법칙은 다양한 수로 이루어진 배열이 있을 때 주어진 수들을 M번 더하여 가장 큰수를 만드는 방법이다. 단, 배열의 특정한 인덱스에 해당하는 수가 연속해서 K번을 초과하여 더해질 수 없는 것이 이 법칙의 특징이다.
*/
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
// N, M, K를 공백을 기준으로 구분하여 입력 받기
int n = sc.nextInt();
int m = sc.nextInt();
int k = sc.nextInt();
// N개의 수를 공백을 기준으로 구분하여 입력 받기
int[] arr = new int[n];
for (int i = 0; i < n; i++) {
arr[i] = sc.nextInt();
}
Arrays.sort(arr); // 입력 받은 수들 정렬하기
int first = arr[n - 1]; // 가장 큰 수
int second = arr[n - 2]; // 두 번째로 큰 수
// 가장 큰 수가 더해지는 횟수 계산
int cnt = (m / (k + 1)) * k;
cnt += m % (k + 1);
int result = 0;
result += cnt * first; // 가장 큰 수 더하기
result += (m - cnt) * second; // 두 번째로 큰 수 더하기
System.out.println(result);
}
}