#include <bits/stdc++.h>
using namespace std;
struct p {
  long long q, w, e;
};
p zx[200000], qwe[200000];
bool f(p z, p x) { return z.q < x.q; }
bool f1(p z, p x) { return z.q > x.q; }
double ans;
long long n, k, z, qq, ww, zxc, qw, k1, ma, zxx, ee;
vector<pair<long long, long long> > a[200000];
int main() {
  cin >> n >> k;
  z = 0;
  for (int i = 0; i < n; i++) {
    scanf("%I64d%I64d", &qwe[i].q, &qwe[i].w);
    qwe[i].e = i + 1;
  }
  sort(qwe, qwe + n, f1);
  for (int i = 0; i < n; i++) {
    qq = qwe[i].q;
    ww = qwe[i].w;
    ee = qwe[i].e;
    if (ww == 1 && z < k) {
      a[z++].push_back(make_pair(ee, qq));
    } else {
      zx[k1].q = qq;
      zx[k1++].w = ee;
    }
  }
  sort(zx, zx + k1, f);
  zxc = k1 - 1;
  for (int i = z; i < k; i++) {
    a[i].push_back(make_pair(zx[zxc].w, zx[zxc].q));
    zxc--;
  }
  for (int i = 0; i < z;) {
    if (zxc == -1) break;
    if (zx[zxc].q > a[i][0].second) {
      a[i].push_back(make_pair(zx[zxc].w, zx[zxc].q));
      zxc--;
    } else
      i++;
  }
  if (z < k) {
    for (int i = 0; i <= zxc; i++) {
      a[k - 1].push_back(make_pair(zx[i].w, zx[i].q));
    }
  } else {
    zxx = 0;
    for (int i = 0; i < k; i++)
      if (a[i][0].second < a[zxx][0].second) zxx = i;
    for (int i = 0; i <= zxc; i++) {
      a[zxx].push_back(make_pair(zx[i].w, zx[i].q));
    }
  }
  ans = 0;
  for (int i = 0; i < k; i++) {
    ma = 2000000000;
    for (int j = 0; j < (int)a[i].size(); j++) {
      ans += a[i][j].second;
      ma = min(ma, a[i][j].second);
    }
    if (i < z) {
      ans -= ma;
      ans += ma / 2.0;
    }
  }
  printf("%.1lf\n", ans);
  for (int i = 0; i < k; i++) {
    cout << a[i].size() << " ";
    for (int j = 0; j < (int)a[i].size(); j++) cout << a[i][j].first << " ";
    cout << endl;
  }
  return 0;
}
