#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  vector<vector<pair<int, int> > > cart(k);
  vector<pair<int, int> > x, y;
  for (int i = 0; i < n; i++) {
    int c, t;
    cin >> c >> t;
    if (t == 1) {
      x.push_back({c, i + 1});
    } else {
      y.push_back({c, i + 1});
    }
  }
  sort(x.begin(), x.end());
  reverse(x.begin(), x.end());
  sort(y.begin(), y.end());
  int i = 0;
  for (int j = 0; j < x.size(); j++) {
    if (i == k) {
      cart[k - 1].push_back(x[j]);
    } else {
      cart[i].push_back(x[j]);
      i++;
    }
  }
  for (int j = 0; j < y.size(); j++) {
    if (i == k) {
      cart[k - 1].push_back(y[j]);
    } else {
      cart[i].push_back(y[j]);
      i++;
    }
  }
  double ans = 0;
  for (int i = 0; i < k; i++) {
    sort(cart[i].begin(), cart[i].end());
    if (i < x.size())
      ans += (cart[i][0].first * 1.0) / 2;
    else
      ans += (cart[i][0].first * 1.0);
    for (int j = 1; j < cart[i].size(); j++) {
      ans += cart[i][j].first;
    }
  }
  printf("%.1f\n", ans);
  for (int i = 0; i < k; i++) {
    cout << cart[i].size() << " ";
    for (int j = 0; j < cart[i].size(); j++) {
      cout << cart[i][j].second << " ";
    }
    cout << endl;
  }
  return 0;
}
