#include <bits/stdc++.h>
using namespace std;
int n, m;
struct node {
  double p;
  int id, k;
} cart[1010];
int cmp(node a, node b) {
  if (a.k != b.k) return a.k < b.k;
  return a.p > b.p;
}
vector<int> vec[1010];
int main() {
  int i, j, cnt;
  double minn, tot, tt, ans;
  while (scanf("%d%d", &n, &m) != EOF) {
    cnt = 0;
    minn = 1000000000.0;
    tot = 0.0;
    tt = 0.0;
    for (i = 0; i < n; i++) {
      scanf("%lf%d", &cart[i].p, &cart[i].k);
      cart[i].id = i;
      if (cart[i].k == 1)
        cnt++, tt += cart[i].p;
      else
        tot += cart[i].p;
      minn = cart[i].p > minn ? minn : cart[i].p;
    }
    sort(cart, cart + n, cmp);
    for (i = 0; i < n; i++) vec[i].clear();
    if (cnt < m) {
      for (i = 0; i < m - 1; i++) {
        vec[i].push_back(cart[i].id);
      }
      for (; i < n; i++) {
        vec[m - 1].push_back(cart[i].id);
      }
      ans = (tt / 2) + tot;
    } else {
      double tmp = 0, ttmp = 0;
      for (i = 0; i < m - 1; i++) {
        vec[i].push_back(cart[i].id), tmp += cart[i].p;
      }
      for (; i < n; i++) {
        vec[m - 1].push_back(cart[i].id), ttmp += cart[i].p;
      }
      ans = (tmp + minn) / 2 + (ttmp - minn);
    }
    printf("%.01lf\n", ans);
    for (i = 0; i < m; i++) {
      printf("%d", vec[i].size());
      for (j = 0; j < vec[i].size(); j++) {
        printf(" %d", vec[i][j] + 1);
      }
      printf("\n");
    }
  }
  return 0;
}
