#include <bits/stdc++.h>
using namespace std;
int n, m, S = 0, c, t;
vector<pair<int, int> > stool, pencil;
vector<int> K[1005];
double AC, MN;
int main() {
  scanf("%d%d", &n, &m);
  S = 0;
  for (int i = 0; i < n; i++) {
    scanf("%d%d", &c, &t);
    if (t == 1) {
      ++S;
      stool.push_back(make_pair(-c, i));
    } else
      pencil.push_back(make_pair(c, i));
  }
  AC = 0.0;
  sort(stool.begin(), stool.end());
  if (m > S) {
    for (int i = 0; i < S; i++) {
      AC += -stool[i].first * 0.5;
      K[i].push_back(stool[i].second);
    }
    for (int i = 0; i < n - S; i++) {
      AC += pencil[i].first;
      K[min(S + i, m - 1)].push_back(pencil[i].second);
    }
  } else {
    for (int i = 0; i < m - 1; i++) {
      AC += -stool[i].first * 0.5;
      K[i].push_back(stool[i].second);
    }
    MN = 1e20;
    for (int i = m - 1; i < S; i++) {
      MN = min(MN, -stool[i].first * 1.0);
      K[m - 1].push_back(stool[i].second);
      AC += -stool[i].first;
    }
    for (int i = 0; i < n - S; i++) {
      MN = min(MN, pencil[i].first * 1.0);
      K[m - 1].push_back(pencil[i].second);
      AC += pencil[i].first;
    }
    AC -= MN * 0.5;
  }
  printf("%.1lf\n", AC);
  for (int i = 0; i < m; i++) {
    int siz = K[i].size();
    printf("%d", siz);
    for (int j = 0; j < siz; j++)
      printf(" %d", K[i][j] + 1, j == siz - 1 ? '\n' : ' ');
    printf("\n");
  }
  return 0;
}
