#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
inline void chkmax(T& x, U y) {
  if (x < y) x = y;
}
template <typename T, typename U>
inline void chkmin(T& x, U y) {
  if (y < x) x = y;
}
const int MAXN = 1111;
int id[MAXN], cost[MAXN], tp[MAXN], ret[MAXN];
int chk[MAXN];
vector<int> V[MAXN];
bool cmp(int x, int y) { return cost[x] < cost[y]; }
int main() {
  int n, m;
  cin >> n >> m;
  int tot = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%d%d", &cost[i], &tp[i]), id[i] = i;
  }
  sort(id + 1, id + n + 1, cmp);
  int cnt = 0, i;
  long long ans = 0;
  int rem = n;
  for (i = n; i > 0 && cnt < m; i--) {
    int u = id[i];
    if (chk[u]) continue;
    chk[u] = ++cnt;
    rem--;
    if (tp[u] == 2 && rem > m - cnt) {
      int v = 0;
      for (int j = i - 1; j > 0; j--) {
        int w = id[j];
        if (chk[w]) continue;
        if (tp[w] == 1) {
          v = w;
          break;
        }
      }
      if (v) {
        chk[v] = cnt;
        rem--;
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    int u = id[i];
    if (!chk[u]) chk[u] = min(m, ++cnt);
  }
  for (int i = 1; i <= m; i++) ret[i] = 1e9 + 5;
  for (int i = 1; i <= n; i++) {
    ans += 2 * cost[i];
    chkmin(ret[chk[i]], cost[i]);
    V[chk[i]].push_back(i);
  }
  for (int i = 1; i <= m; i++) {
    bool flg = 0;
    for (int j = 0; !flg && j < V[i].size(); j++) {
      if (tp[V[i][j]] == 1) flg = 1;
    }
    if (flg) ans -= ret[i];
  }
  printf("%.1lf\n", ans * 0.5);
  for (int i = 1; i <= m; i++) {
    printf("%d", V[i].size());
    for (int j = 0; j < V[i].size(); j++) printf(" %d", V[i][j]);
    puts("");
  }
  return 0;
}
