#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long int n, k, num;
  vector<long long int> list;
  cin >> n >> k;
  while (n-- && cin >> num) {
    list.push_back(num);
  }
  sort(list.begin(), list.end());
  for (long long int x : list) {
    cout << x << " ";
  }
  cout << "\n";
  long long int index = 0, sum = 0;
  while (k--) {
    sum += list[index];
    index++;
  }
  cout << sum << "\n";
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  solve();
  return 0;
}
