forked from ndb796/python-for-coding-test
-
Notifications
You must be signed in to change notification settings - Fork 1
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'; // ์ต์ข
๋ต์ ์ถ๋ ฅ
}