#include <bits/stdc++.h>
using namespace std;
int i, j, n, k, ns, np, oc, stools;
int idcart[1005][1005], cart[1005][1005], idst[1005], st[1005], idpen[1005],
    pen[1005];
vector<pair<int, int> > vst, vpen;
int main() {
  scanf("%d %d", &n, &k);
  ns = np = 0;
  for (i = 0; i < n; i++) {
    int c, t;
    scanf("%d %d", &c, &t);
    if (t == 1) {
      vst.push_back(make_pair(c, i + 1));
      ns++;
    } else {
      vpen.push_back(make_pair(c, i + 1));
      np++;
    }
  }
  sort(vst.begin(), vst.end());
  sort(vpen.begin(), vpen.end());
  for (i = 0; i < k && ns - 1 - i >= 0; i++) {
    cart[i][++cart[i][0]] = vst[ns - 1 - i].first;
    idcart[i][++idcart[i][0]] = vst[ns - 1 - i].second;
  }
  stools = oc = i;
  for (i = ns - k - 1; i >= 0; i--) {
    cart[k - 1][++cart[k - 1][0]] = vst[i].first;
    idcart[k - 1][++idcart[k - 1][0]] = vst[i].second;
  }
  j = 0;
  for (i = oc; i < k; i++)
    if (cart[i][0] == 0) {
      idcart[i][++idcart[i][0]] = vpen[j].second;
      cart[i][++cart[i][0]] = vpen[j++].first;
    }
  oc = j;
  for (i = oc; i < np; i++) {
    for (j = 0; j < k - 1; j++)
      if (pen[i] >= cart[j][1]) {
        cart[j][++cart[j][0]] = vpen[i].first;
        idcart[j][++idcart[j][0]] = vpen[i].second;
        break;
      }
    if (j == k - 1) {
      cart[k - 1][++cart[k - 1][0]] = vpen[i].first;
      idcart[k - 1][++idcart[k - 1][0]] = vpen[i].second;
    }
  }
  for (i = 0; i < k; i++) sort(cart[i] + 1, cart[i] + cart[i][0] + 1);
  double price = 0.0;
  for (i = 0; i < k; i++) {
    j = 1;
    if (i < stools) {
      price += cart[i][1] / 2.0;
      j++;
    }
    for (; j <= cart[i][0]; j++) price += cart[i][j];
  }
  printf("%.1f\n", price);
  for (i = 0; i < k; i++) {
    printf("%d ", idcart[i][0]);
    for (j = 1; j <= idcart[i][0]; j++) printf("%d ", idcart[i][j]);
    printf("\n");
  }
  return 0;
}
