#include <bits/stdc++.h>
using namespace std;
struct Node {
  int c, t, id;
  bool operator<(const Node &p) const { return c > p.c; }
} a[1005];
double mv[1005];
bool yes[1005];
vector<pair<int, int> > v[1005];
int main() {
  int n, K;
  cin >> n >> K;
  for (int i = 0; i < n; i++) {
    scanf("%d %d", &a[i].c, &a[i].t);
    a[i].id = i + 1;
  }
  sort(a, a + n);
  fill(mv, mv + n, 1e20);
  int cur = 0;
  for (int i = 0; i < n; i++) {
    if (a[i].t == 1) {
      yes[cur] = 1;
      v[cur].push_back(make_pair(a[i].c, a[i].id));
      mv[cur] = min(mv[cur], a[i].c * 1.0);
      if (cur < K - 1) {
        cur++;
      }
    }
  }
  for (int i = 0; i < n; i++) {
    if (a[i].t == 2) {
      v[cur].push_back(make_pair(a[i].c, a[i].id));
      mv[cur] = min(mv[cur], a[i].c * 1.0);
      if (cur < K - 1) {
        cur++;
      }
    }
  }
  double ret = 0;
  for (int i = 0; i < K; i++) {
    for (int j = 0; j < v[i].size(); j++) {
      ret += v[i][j].first;
    }
    if (yes[i]) {
      ret -= 0.5 * mv[i];
    }
  }
  printf("%.1f\n", ret);
  for (int i = 0; i < K; i++) {
    printf("%d", v[i].size());
    for (int j = 0; j < v[i].size(); j++) {
      printf(" %d", v[i][j].second);
    }
    puts("");
  }
  return 0;
}
