#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 5;
int n, k, c1, c2;
long long ans, maxx;
struct stool {
  long long c;
  int id;
} st[N];
struct piece {
  long long c;
  int id;
} p[N];
bool cmp1(stool u, stool v) { return u.c > v.c; }
bool cmp2(piece u, piece v) { return u.c > v.c; }
vector<int> cart[N];
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; ++i) {
    long long c;
    int t;
    cin >> c >> t;
    ans += c;
    if (t == 1) st[++c1] = (stool){c, i};
    if (t == 2) p[++c2] = (piece){c, i};
  }
  sort(st + 1, st + c1 + 1, cmp1);
  sort(p + 1, p + c2 + 1, cmp2);
  for (int i = 1; i <= min(c1, k - 1); ++i)
    cart[i].push_back(st[i].id), maxx += st[i].c;
  if (c1 >= k - 1) {
    if (c1 >= k) {
      if (p[c2].c)
        maxx += min(st[c1].c, p[c2].c);
      else
        maxx += st[c1].c;
    }
    for (int i = k; i <= c1; ++i) cart[k].push_back(st[i].id);
    for (int i = 1; i <= c2; ++i) cart[k].push_back(p[i].id);
  } else {
    for (int i = 1; i <= c2; ++i) cart[min(i + c1, k)].push_back(p[i].id);
  }
  (ans *= 2) -= maxx;
  printf("%.1lf\n", ans * 0.5);
  for (int i = 1; i <= k; ++i) {
    cout << cart[i].size() << " ";
    for (int j = 0; j < cart[i].size(); ++j) printf("%d ", cart[i][j]);
    puts("");
  }
  return 0;
}
