#include <bits/stdc++.h>
using namespace std;
int dp[1005][1005];
vector<pair<int, int> > sp, pc;
int k, n, p1 = 0, p2 = 0;
int get(int p1, int p2) { return sp.size() - p1 + pc.size() - p2; }
vector<int> v[2000];
int main() {
  double res = 0;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    int p, t;
    cin >> p >> t;
    if (t == 1)
      sp.push_back(pair<int, int>(p, i));
    else
      pc.push_back(pair<int, int>(p, i));
  }
  sort(sp.begin(), sp.end());
  sort(pc.begin(), pc.end());
  reverse(pc.begin(), pc.end());
  reverse(sp.begin(), sp.end());
  for (int i = 0; i < k; i++) {
    int rem = get(p1, p2);
    if (i == k - 1) {
      double mn = 1e10;
      for (int j = p1; j < sp.size(); j++) {
        v[i].push_back(sp[j].second);
        res += sp[j].first;
        mn = min(mn, (double)sp[j].first);
      }
      for (int j = p2; j < pc.size(); j++) {
        v[i].push_back(pc[j].second);
        res += pc[j].first;
        mn = min(mn, (double)pc[j].first);
      }
      if (p1 < sp.size()) res -= mn / 2.;
    } else if (p1 == sp.size()) {
      if (i == k - 1) {
        for (int j = p2; j < pc.size(); j++)
          v[i].push_back(pc[j].second), res += pc[j].first;
      } else
        v[i].push_back(pc[p2].second), res += pc[p2++].first;
    } else if (p2 == pc.size()) {
      if (i == k - 1) {
        for (int j = p1; j < sp.size(); j++)
          v[i].push_back(sp[j].second), res += sp[j].first;
        res -= (double)(sp[p1].first) / 2.;
      } else
        v[i].push_back(sp[p1].second), res += (double)sp[p1++].first / 2.;
    } else
      v[i].push_back(sp[p1].second), res += (double)sp[p1++].first / 2.;
  }
  printf("%.1lf\n", res);
  for (int i = 0; i < k; i++) {
    cout << v[i].size();
    for (int j = 0; j < v[i].size(); j++) cout << ' ' << v[i][j] + 1;
    cout << endl;
  }
  return 0;
}
