#include <bits/stdc++.h>
using namespace std;
struct Itm {
  int val;
  int id;
  Itm(int v = 0, int i = 0) : val(v), id(i) {}
  friend bool operator<(const Itm& a, const Itm& b) { return a.val > b.val; }
} I[1015], S[1015];
vector<int> car[1015];
int main() {
  int n, m;
  while (~scanf("%d%d", &n, &m)) {
    int Ic = 0, Sc = 0;
    for (int i = 0; i < n; i++) {
      int v, k;
      scanf("%d%d", &v, &k);
      if (k == 1) {
        S[Sc++] = Itm(v, i + 1);
      } else if (k == 2) {
        I[Ic++] = Itm(v, i + 1);
      }
    }
    sort(S, S + Sc);
    for (int i = 0; i < 1005; i++) car[i].clear();
    int TT = 0, tIc = 0;
    double ans = 0;
    for (; TT < Sc; TT++) {
      if (TT >= m - 1) break;
      car[TT].push_back(S[TT].id);
      ans += S[TT].val * 0.5;
    }
    if (TT == Sc) {
      for (int i = TT; i < m - 1; tIc++, i++) {
        car[i].push_back(I[tIc].id);
        ans += I[tIc].val;
      }
      for (; tIc < Ic; tIc++) {
        car[m - 1].push_back(I[tIc].id);
        ans += I[tIc].val;
      }
    } else {
      int mmin = 0x7fffffff;
      for (; TT < Sc; TT++) {
        if (mmin > S[TT].val) mmin = S[TT].val;
        car[m - 1].push_back(S[TT].id);
        ans += S[TT].val;
      }
      for (; tIc < Ic; tIc++) {
        if (mmin > I[tIc].val) mmin = I[tIc].val;
        car[m - 1].push_back(I[tIc].id);
        ans += I[tIc].val;
      }
      ans -= mmin * 0.5;
    }
    printf("%.1f\n", ans);
    for (int i = 0; i < m; i++) {
      printf("%d", car[i].size());
      for (int j = 0; j < car[i].size(); j++) {
        printf(" %d", car[i][j]);
      }
      puts("");
    }
  }
}
