#include <bits/stdc++.h>
using namespace std;
template <class t, class u>
void chmax(t &first, u second) {
  if (first < second) first = second;
}
template <class t, class u>
void chmin(t &first, u second) {
  if (second < first) first = second;
}
struct item {
  int index;
  int cost;
};
vector<item> stools, pencils;
vector<vector<item> > RED, WHITE;
vector<int> red_v;
bool lesser(struct item &left, struct item &right) {
  return left.cost < right.cost;
}
int main() {
  int n, k;
  scanf("%d", &n);
  scanf("%d", &k);
  for (int rep = 0; rep < n; ++rep) {
    int cost, type;
    scanf("%d", &cost);
    scanf("%d", &type);
    if (type == 1) {
      stools.push_back({rep, cost});
    } else {
      pencils.push_back({rep, cost});
    }
  }
  sort(stools.begin(), stools.end(), lesser);
  int numStools = int(stools.size());
  int r = min(k, numStools), w = k - r;
  RED.resize(r);
  red_v.assign(r, 0);
  for (int rep = 0; rep < r; ++rep) {
    RED[rep].push_back(stools.back());
    red_v[rep] = stools.back().cost;
    stools.pop_back();
  }
  if (w > 0) {
    WHITE.resize(w);
    assert(int(pencils.size()) >= w);
    for (int rep = 0; rep < w; ++rep) {
      WHITE[rep].push_back(pencils.back());
      pencils.pop_back();
    }
    while (!pencils.empty()) {
      WHITE[w - 1].push_back(pencils.back());
      pencils.pop_back();
    }
    assert(pencils.empty());
  } else {
    assert(k == r);
    while (!stools.empty()) {
      RED[r - 1].push_back(stools.back());
      assert(stools.back().cost <= red_v[r - 1]);
      red_v[r - 1] = stools.back().cost;
      stools.pop_back();
    }
    assert(stools.empty());
    while (!pencils.empty()) {
      RED[r - 1].push_back(pencils.back());
      red_v[r - 1] = min(red_v[r - 1], pencils.back().cost);
      pencils.pop_back();
    }
    assert(pencils.empty());
  }
  long long int sum = 0LL;
  for (int rep = 0; rep < r; rep++) sum += red_v[rep];
  long long int total_cost = 0LL;
  for (vector<item> &p : RED) {
    for (auto &pi : p) total_cost += pi.cost;
  }
  for (vector<item> &p : WHITE) {
    for (auto &pi : p) total_cost += pi.cost;
  }
  total_cost -= sum;
  if (sum & 1)
    printf("%lld.5\n", sum / 2 + total_cost);
  else
    printf("%lld.0\n", sum / 2 + total_cost);
  for (vector<item> &p : RED) {
    printf("%ld ", p.size());
    for (auto &pi : p) printf("%d ", pi.index + 1);
    printf("\n");
  }
  for (vector<item> &p : WHITE) {
    printf("%ld ", p.size());
    for (auto &pi : p) printf("%d ", pi.index + 1);
    printf("\n");
  }
  return 0;
}
