forked from ndb796/python-for-coding-test
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path2.java
More file actions
34 lines (25 loc) ยท 983 Bytes
/
2.java
File metadata and controls
34 lines (25 loc) ยท 983 Bytes
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
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);
}
}