#include <bits/stdc++.h>
using namespace std;
int main(int argc, char *argv[]) {
  int n, k, tmp;
  double sum = 0;
  vector<pair<long, int> > tab, kar;
  vector<vector<pair<long, int> > > v;
  cin >> n >> k;
  v.resize(k);
  for (int i = 0; i < n; i++) {
    long type, cost;
    cin >> cost >> type;
    pair<long, int> p;
    p.first = cost;
    p.second = i + 1;
    if (type == 1) {
      tab.push_back(p);
    } else {
      kar.push_back(p);
    }
  }
  sort(tab.begin(), tab.end());
  tmp = 0;
  for (int i = tab.size() - 1; i >= 0; i--) {
    v[tmp].push_back(tab[i]);
    if (tmp < k - 1) tmp++;
  }
  for (int i = 0; i < kar.size(); i++) {
    v[tmp].push_back(kar[i]);
    if (tmp < k - 1) tmp++;
  }
  sort(v[k - 1].begin(), v[k - 1].end());
  for (int i = 0; i < k; i++) {
    bool b = false;
    if (i < tab.size()) b = true;
    for (int j = 0; j < v[i].size(); j++) {
      if (b && j == 0) {
        sum += (double)v[i][j].first * 0.5;
      } else {
        sum += (double)v[i][j].first;
      }
    }
  }
  printf("%0.1f%s", sum, "\n");
  for (int i = 0; i < k; i++) {
    cout << v[i].size() << " ";
    for (int j = 0; j < v[i].size(); j++) {
      cout << v[i][j].second << " ";
    }
    cout << endl;
  }
  return 0;
}
