#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  vector<pair<int, int> > a, b;
  long long ans = 0;
  int res = 1000000000;
  for (int i = 0; i < n; ++i) {
    int x, y;
    cin >> x >> y;
    ans += x;
    res = min(res, x);
    if (y == 1)
      a.push_back(make_pair(x, i));
    else
      b.push_back(make_pair(x, i));
  }
  ans *= 2;
  sort((a).begin(), (a).end());
  reverse((a).begin(), (a).end());
  for (int i = 0; i < min(((int)a.size()), k - 1); ++i) ans -= a[i].first;
  if (((int)a.size()) > k - 1) ans -= res;
  cout << ans / 2;
  if (ans % 2 == 1)
    cout << ".5" << endl;
  else
    cout << ".0" << endl;
  if (((int)a.size()) == k) {
    for (int i = 0; i < k - 1; ++i)
      cout << "1"
           << " " << a[i].second + 1 << endl;
    cout << n - (k - 1) << " ";
    cout << a[k - 1].second + 1 << " ";
    for (int i = 0; i < ((int)b.size()); ++i) cout << b[i].second + 1 << " ";
    cout << endl;
  }
  if (((int)a.size()) > k) {
    for (int i = 0; i < k - 1; ++i)
      cout << "1"
           << " " << a[i].second + 1 << endl;
    cout << n - (k - 1) << " ";
    for (int i = k - 1; i < ((int)a.size()); ++i)
      cout << a[i].second + 1 << " ";
    for (int i = 0; i < ((int)b.size()); ++i) cout << b[i].second + 1 << " ";
    cout << endl;
  }
  if (((int)a.size()) < k) {
    for (int i = 0; i < ((int)a.size()); ++i)
      cout << "1"
           << " " << a[i].second + 1 << endl;
    for (int i = 0; i < k - ((int)a.size()) - 1; ++i)
      cout << "1"
           << " " << b[i].second + 1 << endl;
    cout << n - (k - 1) << " ";
    for (int i = k - ((int)a.size()) - 1; i < ((int)b.size()); ++i)
      cout << b[i].second + 1 << " ";
    cout << endl;
  }
  int x;
  cin >> x;
  return 0;
}
