#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  int n, k;
  cin >> n >> k;
  vector<pair<int, int> > St, Pen;
  double sum = 0;
  for (int i = (1); i <= (n); ++i) {
    int c, type;
    cin >> c >> type;
    sum += c;
    pair<int, int> elem = make_pair(c, i);
    if (type == 1)
      St.push_back(elem);
    else
      Pen.push_back(elem);
  }
  int s = (int)(St).size();
  sort(St.begin(), St.end(), greater<pair<int, int> >());
  vector<vector<pair<int, int> > > cart(k);
  vector<bool> discount(k, 0);
  int j = 0;
  for (int i = (0); i <= ((int)(St).size() - 1); ++i) {
    cart[j].push_back(St[i]);
    discount[j] = 1;
    if (j < k - 1) j++;
  }
  for (int i = (0); i <= ((int)(Pen).size() - 1); ++i) {
    cart[j].push_back(Pen[i]);
    if (j < k - 1) j++;
  }
  for (int i = (0); i <= ((int)(cart).size() - 1); ++i)
    sort(cart[i].begin(), cart[i].end());
  for (int i = (0); i <= ((int)(cart).size() - 1); ++i)
    if (discount[i]) sum -= ((double)cart[i][0].first) / 2.0;
  cout.precision(1);
  cout << fixed << sum << '\n';
  for (int i = (0); i <= ((int)(cart).size() - 1); ++i) {
    cout << (int)(cart[i]).size() << ' ';
    for (int j = (0); j <= ((int)(cart[i]).size() - 1); ++j)
      cout << cart[i][j].second << ' ';
    cout << '\n';
  }
  return 0;
}
