#include <bits/stdc++.h>
using namespace std;
const long long inf = (long long)1e+9 + 7ll;
const long long linf = (long long)1e+18 + 7ll;
const long double eps = (long double)1e-9;
const long double pi = acosl((long double)-1.0);
const int alph = 26;
static char buff[(int)2e6 + 17];
const int maxn = (int)2e5 + 17;
struct item {
  int c, t, i;
  item() {}
};
bool operator<(item a, item b) {
  return a.c < b.c || (a.c == b.c && a.t < b.t);
}
int n, k;
item p[maxn];
vector<int> ans[maxn];
bool read() {
  if (scanf("%d %d", &n, &k) != 2) return false;
  for (int i = 0; i < n; ++i) scanf("%d %d", &p[i].c, &p[i].t), p[i].i = i;
  return true;
}
void solve() {
  sort(p, p + n);
  int j = 0;
  for (int i = n - 1; i >= 0; --i) {
    ans[j].push_back(i);
    if (p[i].t == 1 && j < k - 1) ++j;
  }
  for (int i = 0; i < k; ++i) reverse(ans[i].begin(), ans[i].end());
  for (int i = 0; i < k; ++i)
    if (ans[i].empty()) {
      for (int j = 0; j < k; ++j)
        if (((int)(ans[j].size())) > 1) {
          ans[i].push_back(ans[j].back());
          ans[j].pop_back();
          break;
        }
    }
  long long ansi = 0;
  for (int i = 0; i < k; ++i) {
    bool good = false;
    for (int j = 0; j < ((int)(ans[i].size())); ++j)
      ansi += 2ll * p[ans[i][j]].c, good |= int(p[ans[i][j]].t == 1);
    if (good) ansi -= p[ans[i][0]].c;
  }
  printf("%.1f\n", (double)ansi / 2);
  for (int i = 0; i < k; ++i) {
    printf("%d ", ((int)(ans[i].size())));
    for (auto j : ans[i]) printf("%d ", p[j].i + 1);
    printf("\n");
  }
}
int main() {
  while (read()) solve();
  return 0;
}
