#include <bits/stdc++.h>
using namespace std;
struct bb {
  int x, o, va, l;
  int a[1111], b[1111];
} box[1111];
struct pi {
  int x, o;
} a[1111], b[1111];
bool cp1(pi x, pi y) { return x.x > y.x; }
bool cp2(pi x, pi y) { return x.x < y.x; }
int main() {
  int n, k;
  scanf("%d %d", &n, &k);
  int x, y, e = 0, h = 0;
  for (int i = 0; i < n; i++) {
    scanf("%d %d", &x, &y);
    if (y == 2) {
      a[e].x = x;
      a[e++].o = i + 1;
    } else {
      b[h].x = x;
      b[h++].o = i + 1;
    }
  }
  sort(b, b + h, cp1);
  if (h > k) {
    for (int i = 0; i < k; i++) {
      box[i].a[box[i].l] = b[i].x;
      box[i].b[box[i].l++] = b[i].o;
      box[i].va = b[i].x;
    }
    for (int i = k; i < h; i++) {
      a[e].x = b[i].x;
      a[e++].o = b[i].o;
    }
  } else {
    for (int i = 0, j = 0; i < k, j < h; i++, j++) {
      box[i].a[box[i].l] = b[j].x;
      box[i].b[box[i].l++] = b[j].o;
      box[i].va = b[j].x;
    }
  }
  sort(a, a + e, cp2);
  int st = 0;
  for (int i = k - 1; i >= 0; i--)
    if (box[i].l == 0) {
      box[i].a[box[i].l] = a[st].x;
      box[i].b[box[i].l++] = a[st++].o;
      box[i].va = -1;
    }
  for (int j = st; j < e; j++) {
    box[k - 1].a[box[k - 1].l] = a[j].x;
    box[k - 1].b[box[k - 1].l++] = a[j].o;
    if (box[k - 1].va != -1) {
      if (box[k - 1].va > a[j].x) box[k - 1].va = a[j].x;
    }
  }
  double ans = 0;
  for (int i = 0; i < k; i++) {
    for (int j = 0; j < box[i].l; j++) {
      ans += (double)box[i].a[j];
    }
    if (box[i].va != -1) ans -= 0.5 * box[i].va;
  }
  printf("%.1f\n", ans);
  for (int i = 0; i < k; i++) {
    printf("%d ", box[i].l);
    for (int j = 0; j < box[i].l; j++) {
      printf("%d ", box[i].b[j]);
    }
    puts("");
  }
  return 0;
}
