#include <bits/stdc++.h>
using namespace std;
struct itom {
  unsigned long long int price;
  int no;
};
bool cmp(itom a, itom b) { return a.price < b.price; }
int main() {
  int n, k;
  cin >> n >> k;
  vector<itom> stool;
  vector<itom> pencil;
  for (int i = 0; i < n; i++) {
    unsigned long long int a;
    int b;
    cin >> a >> b;
    if (b == 1) {
      itom c;
      c.price = a * 10;
      c.no = i;
      stool.push_back(c);
    } else {
      itom c;
      c.price = a * 10;
      c.no = i;
      pencil.push_back(c);
    }
  }
  if (stool.size()) sort(stool.begin(), stool.end(), cmp);
  vector<vector<itom>> ans;
  ans.resize(k);
  unsigned long long int total = 0;
  int i = 0;
  while (stool.size()) {
    if (i < k - 1) {
      ans[i].push_back(stool.back());
      stool.pop_back();
      total += ans[i].back().price / 2;
      i++;
    } else {
      ans[i].push_back(stool.back());
      stool.pop_back();
      if (stool.size())
        total += ans[i].back().price;
      else
        total += ans[i].back().price / 2;
    }
  }
  if (ans[i].size() == 0)
    while (pencil.size()) {
      ans[i].push_back(pencil.back());
      pencil.pop_back();
      total += ans[i].back().price;
      if (i < k - 1) i++;
    }
  else {
    unsigned long long int mins = ans[i].back().price;
    while (pencil.size()) {
      total = total + mins / 2 + pencil.back().price;
      mins = min(pencil.back().price, mins);
      total -= mins / 2;
      ans[i].push_back(pencil.back());
      pencil.pop_back();
    }
  }
  if (total % 10)
    cout << total / 10 << ".5" << endl;
  else
    cout << total / 10 << ".0" << endl;
  for (int i = 0; i < k; i++) {
    cout << ans[i].size() << " ";
    for (int j = 0; j < ans[i].size(); j++) cout << ans[i][j].no + 1 << " ";
    cout << endl;
  }
  return 0;
}
