1 //It is made by Awson on 2017.11.4
2 #include <map>
3 #include <set>
4 #include <cmath>
5 #include <ctime>
6 #include <queue>
7 #include <stack>
8 #include <cstdio>
9 #include <string>
10 #include <vector>
11 #include <cstdlib>
12 #include <cstring>
13 #include <iostream>
14 #include <algorithm>
15 #define LL long long
16 #define Max(a, b) ((a) > (b) ? (a) : (b))
17 #define Min(a, b) ((a) < (b) ? (a) : (b))
18 #define Abs(a) ((a) < 0 ? (-(a)) : (a))
19 using namespace std;
20 const int N = 100000;
21
22 int n, k;
23 struct node {
24 LL h, v;
25 node() {
26 }
27 node(LL _h, LL _v) {
28 h = _h, v = _v;
29 }
30 bool operator < (const node &b) const {
31 return v == b.v ? h > b.h : v > b.v;
32 }
33 }a;
34 priority_queue<node>Q;
35
36 void work() {
37 scanf("%d%d", &n, &k);
38 for (int i = 1; i <= n; i++) {
39 scanf("%lld", &a.v); a.h = 0;
40 Q.push(a);
41 }
42 int rest = 0;
43 if ((n-1)%(k-1)) rest = k-1-((n-1)%(k-1));
44 for (int i = 1; i <= rest; i++) Q.push(node(0, 0));
45 LL ans = 0;
46 while (Q.size() != 1) {
47 LL tmp = 0, height = 0;
48 for (int i = 1; i <= k; i++) {
49 tmp += Q.top().v, height = Max(height, Q.top().h); Q.pop();
50 }
51 ans += tmp;
52 Q.push(node(height+1, tmp));
53 }
54 printf("%lld\n%lld\n", ans, Q.top().h);
55 }
56 int main() {
57 work();
58 return 0;
59 }