#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > stool;
vector<pair<int, int> > pencil;
vector<pair<int, int> > ans[1111];
bool iss[100005];
int main() {
  int n = ({
    int x;
    scanf("%d", &x);
    x;
  }),
      k = ({
        int x;
        scanf("%d", &x);
        x;
      });
  for (int _n(n), i(0); i < _n; i++) {
    int c = ({
      int x;
      scanf("%d", &x);
      x;
    }),
        t = ({
          int x;
          scanf("%d", &x);
          x;
        });
    if (t == 1)
      stool.push_back(make_pair(c, i + 1));
    else
      pencil.push_back(make_pair(c, i + 1));
    if (t == 1) iss[i + 1] = true;
  }
  sort((stool).begin(), (stool).end());
  sort((pencil).begin(), (pencil).end());
  int si = int(stool.size()) - 1, pi = int(pencil.size()) - 1,
      sleft = int(stool.size()), pleft = int(pencil.size());
  int ind = 0;
  for (int i = 0; i < min(int(stool.size()), k); i++)
    ans[ind++].push_back(stool[si--]);
  if (ind == k) {
    while (si >= 0) ans[k - 1].push_back(stool[si--]);
    while (pi >= 0) ans[k - 1].push_back(pencil[pi--]);
  } else {
    while (ind < k) ans[ind++].push_back(pencil[pi--]);
    while (pi >= 0) ans[k - 1].push_back(pencil[pi--]);
  }
  double score = 0;
  for (int _n(k), i(0); i < _n; i++) {
    int mn = (int)1e9;
    bool sss = false;
    for (typeof((ans[i]).begin()) it = (ans[i]).begin(); it != (ans[i]).end();
         it++) {
      int cst = it->first, ind = it->second;
      mn = min(mn, cst);
      if (iss[ind]) sss = true;
      score += cst;
    }
    if (sss) score -= mn / 2.;
  }
  printf("%.1lf\n", score);
  for (int _n(k), i(0); i < _n; i++) {
    printf("%d", int(ans[i].size()));
    for (typeof((ans[i]).begin()) it = (ans[i]).begin(); it != (ans[i]).end();
         it++)
      printf(" %d", it->second);
    puts("");
  }
  return 0;
}
