-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path01_greedy.cpp
More file actions
47 lines (38 loc) · 816 Bytes
/
01_greedy.cpp
File metadata and controls
47 lines (38 loc) · 816 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
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
using namespace std;
int main() {
ios::sync_with_stdio(false);
int N,M,K;
int buff;
int sum=0;
int count=0;
vector<int> v;
cin >> N >> M >> K;
for (int i=0; i<N; i++) {
cin >> buff;
v.push_back(buff);
}
sort(v.begin(), v.end(), greater<int>());
// for (auto itr = v.begin(); itr!=v.end(); ++itr) { // auto 개꿀
// cout << *itr << endl;
// }
while (true) {
for (int i=0; i<K; i++) {
sum += v[0];
count++;
if (count == M) {
break;
}
}
sum += v[1];
count++;
if (count == M) {
break;
}
}
printf("%d\n",sum);
return 0;
}