#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-10, inf = 1e10;
int n, k, type[1010];
vector<int> carr[1010];
vector<pair<int, int> > stool, pencil, input;
int main() {
  scanf("%d%d", &n, &k);
  for (int(i) = 0; (i) < (n); (i)++) {
    int c, t;
    scanf("%d%d", &c, &t);
    ((t == 1) ? stool : pencil).push_back(make_pair(c, i));
    input.push_back(make_pair(c, i));
    type[i] = t;
  }
  sort(stool.rbegin(), stool.rend());
  sort(pencil.rbegin(), pencil.rend());
  long long ans = 0;
  int i = 0, j = 0, lasthas = 0, minAss = numeric_limits<int>::max();
  while (i < k - 1 && i < (int((stool).size())))
    ans += stool[i].first, carr[i].push_back(stool[i].second), i++;
  while (i + j < k - 1 && j < (int((pencil).size())))
    ans += 2 * pencil[j].first, carr[i + j].push_back(pencil[j].second), j++;
  while (i < (int((stool).size())))
    minAss = min(minAss, stool[i].first), ans += 2 * stool[i].first,
    carr[k - 1].push_back(stool[i].second), i++, lasthas = 1;
  while (j < (int((pencil).size())))
    minAss = min(minAss, pencil[j].first), ans += 2 * pencil[j].first,
    carr[k - 1].push_back(pencil[j].second), j++;
  if (lasthas) ans -= minAss;
  cout << (ans / 2) << '.' << (ans % 2 * 5) << '\n';
  for (int(i) = 0; (i) < (k); (i)++) {
    printf("%d", (int((carr[i]).size())));
    for (int(j) = 0; (j) < ((int((carr[i]).size()))); (j)++)
      printf(" %d", carr[i][j] + 1);
    printf("\n");
  }
  return 0;
}
