#include <bits/stdc++.h>
typedef struct tov {
  long long p;
  long long typ;
  long long num;
} tov;
tov a[1010];
long long ans[1010][1010];
long long lens[1010];
long long n, k;
int main(void) {
  int i, j;
  scanf("%I64d%I64d", &n, &k);
  for (i = 0; i < n; ++i) {
    scanf("%I64d%I64d", &a[i].p, &a[i].typ);
    a[i].num = i + 1;
  }
  for (i = 0; i < n; ++i) {
    for (j = 0; j < n - i - 1; ++j) {
      if (a[j].p < a[j + 1].p) {
        tov tmp = a[j];
        a[j] = a[j + 1];
        a[j + 1] = tmp;
      }
    }
  }
  long long p = 0, answ1 = 0, answ2 = 0, bad;
  for (i = 0; i < n; ++i) {
    if (p == k) {
      break;
    }
    if (a[i].typ == 1) {
      ans[p][lens[p]++] = a[i].num;
      ++p;
      answ1 += a[i].p;
      if (p == k) {
        bad = a[i].p;
      }
      a[i].p = -1;
    }
  }
  if (p == k) {
    for (i = 0; i < n; ++i) {
      if (a[i].p > 0) {
        ans[k - 1][lens[k - 1]++] = a[i].num;
        answ2 += a[i].p;
      }
    }
    if (a[n - 1].p > 0) {
      answ1 -= bad;
      answ2 += bad;
      answ1 += a[n - 1].p;
      answ2 -= a[n - 1].p;
    }
  } else {
    for (i = 0; i < n; ++i) {
      if (p == k) {
        break;
      }
      if (a[i].typ == 2) {
        ans[p][lens[p]++] = a[i].num;
        answ2 += a[i].p;
        ++p;
      }
    }
    for (; i < n; ++i) {
      if (a[i].typ == 2) {
        ans[k - 1][lens[k - 1]++] = a[i].num;
        answ2 += a[i].p;
      }
    }
  }
  printf("%I64d", answ2 + answ1 / 2);
  if (answ1 % 2 == 1) {
    printf(".5\n");
  } else {
    printf(".0\n");
  }
  for (i = 0; i < k; ++i) {
    printf("%I64d ", lens[i]);
    for (j = 0; j < lens[i]; ++j) {
      printf("%I64d ", ans[i][j]);
    }
    printf("\n");
  }
  return 0;
}
