#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, x, y;
  int i, j = 0;
  double temp = 0;
  scanf("%d%d", &n, &m);
  vector<pair<int, int> > second, first, voc(n);
  vector<vector<int> > answer(m, vector<int>());
  for (i = 0; i < n; i++) {
    scanf("%d%d", &voc[i].first, &voc[i].second);
    if (voc[i].second == 1) {
      first.push_back(make_pair(voc[i].first, i));
    } else {
      second.push_back(make_pair(voc[i].first, i));
    }
  }
  sort((first).begin(), (first).end());
  sort((second).begin(), (second).end());
  for (i = 0; i < first.size() && i < m; i++) {
    answer[i].push_back(first[first.size() - i - 1].second);
  }
  for (; i < first.size(); i++) {
    answer[m - 1].push_back(first[first.size() - i - 1].second);
  }
  for (int t = i; t < m; t++, j++) {
    answer[t].push_back(second[j].second);
  }
  i = j, j = second.size() - 1;
  for (int t = 0; t < m && j >= i; t++) {
    if (second[j].first > voc[answer[t].back()].first) {
      answer[t].push_back(second[j].second);
      j--;
    }
  }
  while (j >= i && j >= 0) {
    answer[m - 1].push_back(second[j].second);
    j--;
  }
  for (i = 0; i < m; i++) {
    x = 0, y = ~(1 << 31);
    for (j = 0; j < answer[i].size(); j++) {
      temp += voc[answer[i][j]].first;
      x |= (int)((voc[answer[i][j]].second == 1));
      y = min(y, voc[answer[i][j]].first);
    }
    if (x) {
      temp -= y * 0.5;
    }
  }
  printf("%.1lf\n", temp);
  for (i = 0; i < m; i++) {
    printf("%d ", answer[i].size());
    for (j = 0; j < answer[i].size(); j++) {
      printf("%d ", answer[i][j] + 1);
    }
    putchar('\n');
  }
  return 0;
}
