- Notifications
You must be signed in to change notification settings - Fork 846
/
Copy path2.java
34 lines (25 loc) · 983 Bytes
/
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
importjava.util.*;
publicclassMain {
publicstaticvoidmain(String[] args) {
Scannersc = newScanner(System.in);
// N, M, K를 공백을 기준으로 구분하여 입력 받기
intn = sc.nextInt();
intm = sc.nextInt();
intk = sc.nextInt();
// N개의 수를 공백을 기준으로 구분하여 입력 받기
int[] arr = newint[n];
for (inti = 0; i < n; i++) {
arr[i] = sc.nextInt();
}
Arrays.sort(arr); // 입력 받은 수들 정렬하기
intfirst = arr[n - 1]; // 가장 큰 수
intsecond = arr[n - 2]; // 두 번째로 큰 수
// 가장 큰 수가 더해지는 횟수 계산
intcnt = (m / (k + 1)) * k;
cnt += m % (k + 1);
intresult = 0;
result += cnt * first; // 가장 큰 수 더하기
result += (m - cnt) * second; // 두 번째로 큰 수 더하기
System.out.println(result);
}
}