#include <bits/stdc++.h>
using namespace std;
vector<pair<long long, long long> > a, b;
bool cmp(pair<long long, long long> a, pair<long long, long long> b) {
  if (a.first == b.first) return a.second < b.second;
  return a.first > b.first;
}
vector<pair<long long, long long> > r[1001];
bool mark[1001];
int main() {
  int n, k, t;
  long long c;
  memset(mark, false, sizeof mark);
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> c >> t;
    if (t == 1)
      mark[i] = true, a.push_back(make_pair(c, i));
    else
      b.push_back(make_pair(c, i));
  }
  sort(a.begin(), a.end(), cmp);
  sort(b.begin(), b.end(), cmp);
  int j = 0;
  for (int i = 0; i < a.size(); i++) {
    if (j < k - 1)
      r[j++].push_back(a[i]);
    else
      r[j].push_back(a[i]);
  }
  for (int i = 0; i < b.size(); i++) {
    if (j < k - 1)
      r[j++].push_back(b[i]);
    else
      r[j].push_back(b[i]);
  }
  double res = 0;
  for (int i = 0; i < k; i++) {
    long long mn = 0;
    if (mark[r[i][0].second]) mn = 1000000003;
    for (int j = 0; j < r[i].size(); j++) {
      mn = min(mn, r[i][j].first);
      res += r[i][j].first;
    }
    res -= mn / 2.0;
  }
  cout << setprecision(1) << fixed << res << endl;
  for (int i = 0; i < k; i++) {
    cout << r[i].size();
    for (int j = 0; j < r[i].size(); j++) cout << " " << r[i][j].second + 1;
    cout << endl;
  }
  return 0;
}
