#include <bits/stdc++.h>
using namespace std;
int main() {
  if (false) {
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
  }
  int n, k;
  cin >> n >> k;
  vector<pair<long long, int> > t, p;
  for (int i = 0; i < n; i++) {
    long long price;
    int type;
    cin >> price >> type;
    if (type == 1) {
      t.push_back(make_pair(price, i));
    } else {
      p.push_back(make_pair(price, i));
    }
  }
  sort(t.begin(), t.end());
  reverse(t.begin(), t.end());
  sort(p.begin(), p.end());
  reverse(p.begin(), p.end());
  vector<vector<pair<long long, int> > > b(k);
  long long price = 0;
  int ii = 0;
  for (; ii < t.size() && ii < k - 1; ii++) {
    b[ii].push_back(t[ii]);
    price += t[ii].first;
  }
  for (; ii < t.size(); ii++) {
    b[k - 1].push_back(t[ii]);
    price += 2 * t[ii].first;
  }
  int jj = 0;
  for (; ii < k - 1 && jj < p.size(); ii++, jj++) {
    b[ii].push_back(p[jj]);
    price += 2 * p[jj].first;
  }
  for (; jj < p.size(); jj++) {
    b[k - 1].push_back(p[jj]);
    price += 2 * p[jj].first;
  }
  if (t.size() >= k) {
    int pm = -1;
    for (int i = 0; i < b[k - 1].size(); i++) {
      if (pm < 0 || pm > b[k - 1][i].first) {
        pm = b[k - 1][i].first;
      }
    }
    price -= pm;
  }
  cout << (price / 2);
  if (price % 2 != 0) {
    cout << ".5";
  } else {
    cout << ".0";
  }
  cout << endl;
  for (int i = 0; i < k; i++) {
    cout << b[i].size();
    for (int j = 0; j < b[i].size(); j++) {
      cout << " ";
      cout << (b[i][j].second + 1);
    }
    cout << endl;
  }
  if (false) {
    fclose(stdin);
    fclose(stdout);
  }
  return 0;
}
