#include <bits/stdc++.h>
using namespace std;
vector<pair<pair<int, int>, int> > a;
int used[1010];
vector<vector<pair<int, int> > > g;
vector<pair<int, int> > tabs;
int cost[1010];
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  a.resize(n);
  g.resize(k);
  for (int i = (0); i < (n); ++i) {
    scanf("%d%d", &a[i].first.first, &a[i].first.second);
    a[i].first.first *= 2;
    cost[i] = a[i].first.first;
    a[i].second = i + 1;
  }
  sort(a.begin(), a.end());
  int to = 0;
  for (int i = n - 1; i >= 0; --i) {
    if (tabs.size() == k) break;
    if (a[i].first.second == 1) {
      tabs.push_back(make_pair(a[i].first.first, to));
      g[to].push_back(make_pair(a[i].first.first, a[i].second));
      to++;
      used[i] = 1;
    }
  }
  for (int i = (0); i < (a.size()); ++i) {
    if (to == k) break;
    if (used[i] == 0) {
      used[i] = 1;
      g[to].push_back(make_pair(a[i].first.first, a[i].second));
      to++;
    }
  }
  for (int i = (0); i < (a.size()); ++i)
    if (used[i] == 0)
      g[k - 1].push_back(make_pair(a[i].first.first, a[i].second));
  for (int i = (0); i < (g.size()); ++i) sort(g[i].begin(), g[i].end());
  long long sum = 0;
  for (int i = (0); i < (g.size()); ++i) {
    for (int j = (0); j < (g[i].size()); ++j) {
      int to = g[i][j].second;
      if ((i < tabs.size()) && (j == 0))
        sum += g[i][j].first / 2;
      else
        sum += g[i][j].first;
    }
  }
  double res = sum / 2.0;
  printf("%.1lf\n", res);
  for (int i = (0); i < (g.size()); ++i) {
    printf("%d", g[i].size());
    for (int j = (0); j < (g[i].size()); ++j) {
      int to = g[i][j].second;
      printf(" %d", to);
    }
    printf("\n");
  }
  return 0;
}
