forked from ndb796/python-for-coding-test
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2.cpp
More file actions
32 lines (24 loc) · 825 Bytes
/
2.cpp
File metadata and controls
32 lines (24 loc) · 825 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
#include <bits/stdc++.h>
using namespace std;
int n, m, k;
vector<int> v;
int main() {
// N, M, K를 공백을 기준으로 구분하여 입력 받기
cin >> n >> m >> k;
// N개의 수를 공백을 기준으로 구분하여 입력 받기
for (int i = 0; i < n; i++) {
int x;
cin >> x;
v.push_back(x);
}
sort(v.begin(), v.end()); // 입력 받은 수들 정렬하기
int first = v[n - 1]; // 가장 큰 수
int second = v[n - 2]; // 두 번째로 큰 수
// 가장 큰 수가 더해지는 횟수 계산
int cnt = (m / (k + 1)) * k;
cnt += m % (k + 1);
int result = 0;
result += cnt * first; // 가장 큰 수 더하기
result += (m - cnt) * second; // 두 번째로 큰 수 더하기
cout << result << '\n'; // 최종 답안 출력
}