#include <bits/stdc++.h>
using namespace std;
struct ans {
  int num, price;
} tmp[100005], d[10005];
int mk[10005];
vector<ans> res[10004];
bool cm(ans a, ans b) { return a.price > b.price; }
int main() {
  int n, m;
  int cnt, value, t;
  int mn;
  double solve;
  int eva;
  while (scanf("%d%d", &n, &m) == 2) {
    memset(mk, 0, sizeof(mk));
    solve = 0;
    cnt = 0;
    eva = 0;
    mn = 1000000002;
    for (int i = 1; i <= n; i++) {
      scanf("%d%d", &value, &t);
      if (t == 1) {
        tmp[cnt].num = i;
        tmp[cnt].price = value;
        cnt++;
      } else {
        d[eva].num = i;
        d[eva].price = value;
        eva++;
      }
    }
    sort(tmp, tmp + cnt, cm);
    int j = 0;
    for (int i = 0; i < cnt; i++, j++) {
      if (i < m) {
        res[i].push_back(tmp[i]);
        mk[i] = 1;
      } else {
        res[m - 1].push_back(tmp[i]);
      }
    }
    if (j < m) {
      int i = 0;
      for (; i < eva && j < m; j++, i++) {
        res[j].push_back(d[i]);
      }
      while (i < eva) {
        res[m - 1].push_back(d[i]);
        i++;
      }
    } else {
      int i = 0;
      while (i < eva) {
        res[m - 1].push_back(d[i]);
        i++;
      }
    }
    solve = 0;
    for (int i = 0; i < m; i++) {
      int l = mn;
      for (int k = 0; k < res[i].size(); k++) {
        if (res[i][k].price < l) l = res[i][k].price;
        solve += res[i][k].price * 1.0;
      }
      if (mk[i]) solve -= l * 1.0 / 2;
    }
    printf("%.1lf\n", solve);
    for (int i = 0; i < m; i++) {
      printf("%d ", res[i].size());
      for (int k = 0; k < res[i].size(); k++) {
        printf("%d ", res[i][k].num);
      }
      printf("\n");
    }
  }
  return 0;
}
