#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000 + 10;
int c[maxn], t[maxn], idx[maxn], ans[maxn];
int n, k;
bool cmp(int i, int j) { return t[i] < t[j] || t[i] == t[j] && c[i] > c[j]; }
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 0; i < n; ++i) {
    scanf("%d%d", &c[i], &t[i]);
    idx[i] = i;
  }
  sort(idx, idx + n, cmp);
  int cnt = 0;
  while (cnt < n && t[idx[cnt]] == 1) ++cnt;
  long long half = 0, full = 0;
  if (cnt < k) {
    for (int i = 0; i < cnt; ++i) {
      ans[idx[i]] = i;
      half += c[idx[i]];
    }
    for (int i = cnt; i < k; ++i) {
      ans[idx[i]] = i;
      full += c[idx[i]];
    }
    for (int i = k; i < n; ++i) {
      ans[idx[i]] = k - 1;
      full += c[idx[i]];
    }
  } else {
    for (int i = 0; i < k - 1; ++i) {
      ans[idx[i]] = i;
      half += c[idx[i]];
    }
    int best = c[idx[k - 1]];
    for (int i = k - 1; i < n; ++i) {
      ans[idx[i]] = k - 1;
      if (c[idx[i]] < best) best = c[idx[i]];
      full += c[idx[i]];
    }
    half += best;
    full -= best;
  }
  printf("%I64d", full + half / 2);
  if (half & 1)
    printf(".5\n");
  else
    printf(".0\n");
  for (int i = 0; i < k; ++i) {
    int tot = 0;
    for (int j = 0; j < n; ++j)
      if (ans[j] == i) ++tot;
    printf("%d", tot);
    for (int j = 0; j < n; ++j)
      if (ans[j] == i) printf(" %d", j + 1);
    puts("");
  }
  return 0;
}
