#include <bits/stdc++.h>
using namespace std;
struct hh {
  int num;
  int c;
};
bool cmp(const hh p, const hh q) { return p.c < q.c; }
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  hh a[1010], b[1010];
  int i;
  int p = 0, q = 0;
  vector<int> ss[1010];
  for (i = 0; i < n; ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    if (y == 1) {
      a[p].num = i + 1;
      a[p++].c = x;
    } else {
      b[q].num = i + 1;
      b[q++].c = x;
    }
  }
  sort(a, a + p, cmp);
  sort(b, b + q, cmp);
  double ans = 0;
  if (p >= k) {
    for (i = 1; i < k; ++i) {
      ans += a[p - i].c * 1.0 / 2;
      ss[i].push_back(a[p - i].num);
    }
    if (q > 0) {
      if (a[0].c > b[0].c) {
        ans += b[0].c * 1.0 / 2;
        ans += a[0].c;
      } else {
        ans += a[0].c * 1.0 / 2;
        ans += b[0].c;
      }
      ss[k].push_back(b[0].num);
    } else
      ans += a[0].c * 1.0 / 2;
    ss[k].push_back(a[0].num);
    for (i = 1; i < q; ++i) {
      ss[k].push_back(b[i].num);
      ans += b[i].c;
    }
    for (i = p - k; i > 0; --i) {
      ss[k].push_back(a[i].num);
      ans += a[i].c;
    }
  } else {
    for (i = 1; i <= p; ++i) {
      ss[i].push_back(a[i - 1].num);
      ans += a[i - 1].c * 1.0 / 2;
    }
    int e = 0;
    for (i = p + 1; i <= k; ++i) {
      ss[i].push_back(b[e].num);
      ans += b[e++].c;
    }
    for (i = e; i < q; ++i) {
      ss[k].push_back(b[i].num);
      ans += b[i].c;
    }
  }
  printf("%.1f\n", ans);
  int j;
  for (i = 1; i <= k; ++i) {
    printf("%d", ss[i].size());
    for (j = 0; j < ss[i].size(); ++j) printf(" %d", ss[i][j]);
    printf("\n");
  }
  return 0;
}
