#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
int n, k, cnt, minn = inf, b[1005];
bool tag[1005];
struct stool {
  int c, id;
  bool operator<(const stool &b) const { return c > b.c; }
} st[1005];
double ans;
long long sum;
int main() {
  scanf("%d %d", &n, &k);
  for (int i = 1, c, t; i <= n; i++) {
    scanf("%d %d", &c, &t), b[i] = c;
    if (t == 2)
      tag[i] = 1, sum += (long long)c;
    else
      st[++cnt] = (stool){c, i};
    minn = min(minn, c);
  }
  sort(st + 1, st + 1 + cnt);
  if (cnt < k) {
    for (int i = 1; i <= cnt; i++) ans += (double)st[i].c * 0.5;
    ans += (double)sum;
    printf("%.1lf\n", ans);
    for (int i = 1; i <= cnt; i++) printf("1 %d\n", st[i].id);
    for (int i = 1; i <= n; i++) {
      if (!tag[i]) continue;
      cnt++;
      if (cnt == k) printf("%d ", n - k + 1);
      if (cnt >= k)
        printf("%d ", i);
      else
        printf("1 %d\n", i);
    }
  } else {
    for (int i = 1; i < k; i++) ans += (double)st[i].c * 0.5;
    for (int i = k; i <= cnt; i++) {
      if (st[i].c == minn)
        minn = -1, ans += (double)st[i].c * 0.5;
      else
        ans += (double)st[i].c;
    }
    for (int i = 1; i <= n; i++) {
      if (!tag[i]) continue;
      if (b[i] == minn)
        minn = -1, ans += (double)b[i] * 0.5;
      else
        ans += (double)b[i];
    }
    printf("%.1lf\n", ans);
    for (int i = 1; i < k; i++) printf("1 %d\n", st[i].id);
    printf("%d ", n - k + 1);
    for (int i = k; i <= cnt; i++) printf("%d ", st[i].id);
    for (int i = 1; i <= n; i++)
      if (tag[i]) printf("%d ", i);
    puts("");
  }
  return 0;
}
