#include <bits/stdc++.h>
using namespace std;
struct point {
  int id, c, t;
} pnt[100006];
bool cmp1(point p1, point p2) {
  if (p1.t != p2.t) return p1.t < p2.t;
  return p1.c > p2.c;
}
int main() {
  int n, k, i, j, cnt, min1;
  double ansn = 0;
  scanf("%d%d", &n, &k), cnt = k - 1;
  for (i = 1; i <= n; i++) scanf("%d%d", &pnt[i].c, &pnt[i].t), pnt[i].id = i;
  sort(pnt + 1, pnt + 1 + n, cmp1);
  for (i = 1; i <= n && cnt && pnt[i].t == 1; i++) {
    ansn += pnt[i].c * 0.5, cnt--;
  }
  if (pnt[i].t == 1) {
    min1 = pnt[i].c, j = i + 1;
    for (; j <= n; j++) {
      if (min1 > pnt[j].c) min1 = pnt[j].c;
    }
  }
  j = i;
  for (; j <= n; j++) {
    ansn += pnt[j].c;
  }
  if (pnt[i].t == 1) ansn -= min1 * 0.5;
  printf("%.1lf\n", ansn);
  for (i = 1; i <= k - cnt - 1; i++) cout << "1 " << pnt[i].id << endl;
  for (; i <= k - 1; i++) cout << "1 " << pnt[i].id << endl;
  cout << n - k + 1;
  for (i = k; i <= n; i++) {
    cout << " " << pnt[i].id;
  }
  cout << endl;
  return 0;
}
