#include "bits/extc++.h"
using namespace std;
template<class T>
using mpq = priority_queue<T, vector<T>, greater<>>;
template<class T, class U = less<T>>
using rt = __gnu_pbds::tree<T, __gnu_pbds::null_type, U, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;
template<class T>
void dbgh(const T &t) {
cerr << t << endl;
}
template<class T, class ...U>
void dbgh(const T &t, const U &...u) {
cerr << t << " | ";
dbgh(u...);
}
#ifdef DEBUG
#define dbg(...) cerr << "L" << __LINE__ << " [" << #__VA_ARGS__ << "]" << ": "; dbgh(__VA_ARGS__)
#else
#define cerr if(false) cerr
#define dbg(...) 1412
#endif
//imagine a language where int = long
#define long int64_t
//typing too hard
#define endl "\n"
#define sz(x) static_cast<int>((x).size())
#define inline inline __attribute__((always_inline))
void solve() {
int n, k;
cin >> n >> k;
mpq<pair<long, int>> pq;
for(int i = 0; i < n; i++) {
long x;
cin >> x;
pq.emplace(x, 0);
}
if(k != 2) {
while(sz(pq) % (k - 1) != 1) {
pq.emplace(0, 0);
}
}
long cans = 0;
while(sz(pq) > 1) {
long ans = 0;
int mans = 0;
for(int i = 0; i < k && sz(pq); i++) {
auto[x, d] = pq.top();
pq.pop();
ans += x;
mans = max(mans, d);
}
cans += ans;
pq.emplace(ans, mans + 1);
}
auto[x, d] = pq.top();
pq.pop();
cout << cans << endl;
cout << d << endl;
}
int main() {
cin.tie(0)->sync_with_stdio(0);
cin.exceptions(ios::failbit);
#ifdef LOCAL
freopen("input.txt", "r", stdin);
#endif
int t = 1;
// cin >> t;
for(int _ = 1; _ <= t; _++) {
dbg(_);
// cout << "Case #" << _ << ": ";
solve();
}
}