Summary Files Commits Branches @commit @diff @stats
path: root / Year 2 / Design and analysis of algorithms / Practicum / Exam1 / 1-Flowers.cpp
blob: 9421332a9a2f23560a6a4bab527aea9c107cd1e4 (plain) (blame)
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
#include <cstdio>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
	int K = 0, N = 0;
	scanf("%d %d", &N, &K);
	vector<int> f;
	int temp = 0;
	for (int i = 0; i < N; i++) {
		scanf("%d", &temp);
		f.push_back(temp);
	}

	sort(f.rbegin(), f.rend());
	long S = 0, p = 1;
	for (int i = 0; i < f.size(); i++) {
		if (i == K * p) p++;
		S += p * f[i];
	}

	printf("%ld", S);
}