#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k, i, j, l, t;
  int s = 0;
  cin >> n;
  cin >> k;
  int a[n];
  for (i = 0; i < n; i++) cin >> a[i];
  for (j = 0; j < n; j++)
    for (l = 0; l < n; l++) {
      if (a[j] <= a[l]) {
        t = a[j];
        a[j] = a[l];
        a[l] = t;
      }
    }
  for (i = 0; i < n; i++) cout << a[i] << "\t";
  cout << "\n";
  for (i = 0; i < k; i++) s += a[i];
  cout << s;
}
