#include <bits/stdc++.h>
using namespace std;
int n, k;
int c[1001], t[1001];
vector<pair<int, int> > tab, pen;
vector<int> res[1001];
int main() {
  scanf("%d %d", &n, &k);
  for (int i = (0), _b(n); i < _b; i++) {
    scanf("%d %d", c + i, t + i);
    if (t[i] == 1)
      tab.push_back(pair<int, int>(c[i], i + 1));
    else
      pen.push_back(pair<int, int>(c[i], i + 1));
  }
  sort(tab.begin(), tab.end());
  reverse(tab.begin(), tab.end());
  while ((int)(tab).size() > k) {
    pen.push_back(tab.back());
    tab.pop_back();
  }
  sort(pen.begin(), pen.end());
  reverse(pen.begin(), pen.end());
  long long ans = 0;
  int from = k - (int)(tab).size();
  for (int i = (0), _b(from); i < _b; i++) {
    res[i].push_back(pen.back().second);
    ans += 2LL * pen.back().first;
    pen.pop_back();
  }
  reverse(pen.begin(), pen.end());
  for (int i = (0), _b((int)(tab).size()); i < _b; i++) {
    res[from + i].push_back(tab[i].second);
    ans += (long long)tab[i].first;
    while ((int)(pen).size() && pen.back().first >= tab[i].first) {
      res[from + i].push_back(pen.back().second);
      ans += 2LL * c[res[from + i].back() - 1];
      pen.pop_back();
    }
  }
  if (!from) {
    reverse(res[k - 1].begin(), res[k - 1].end());
    while ((int)(pen).size()) {
      ans += c[res[k - 1].back() - 1];
      res[k - 1].push_back(pen.back().second);
      ans += c[res[k - 1].back() - 1];
      pen.pop_back();
    }
  } else
    while ((int)(pen).size()) {
      ans += 2LL * pen.back().first;
      res[0].push_back(pen.back().second);
      pen.pop_back();
    }
  printf("%I64d.%d\n", ans / 2, (ans % 2) * 5);
  for (int i = (0), _b(k); i < _b; i++) {
    printf("%d", (int)(res[i]).size());
    for (int j = (0), _b((int)(res[i]).size()); j < _b; j++)
      printf(" %d", res[i][j]);
    printf("\n");
  }
  return 0;
}
