#include <bits/stdc++.h>
using namespace std;
const int INF = 2147483647;
const double PI = 3.141592653589793;
const int N = 1005;
long long res;
int minn, kol[N], juz[N], w, t[N], c[N], i, j, n, k, st;
vector<int> wek[N];
bool cmp(int a, int b) { return c[a] > c[b]; }
int main() {
  scanf("%d %d", &n, &k);
  for (i = 0; i < n; i++) {
    scanf("%d %d", &c[i], &t[i]);
    kol[i] = i;
    juz[i] = 0;
  }
  j = 0;
  sort(kol, kol + n, cmp);
  for (i = 0; i < n; i++) {
    w = kol[i];
    if (t[w] == 1 && j < k) {
      juz[w] = 1;
      wek[j].push_back(w);
      j++;
    }
  }
  for (i = 0; i < n && j < k; i++)
    if (juz[i] == 0) {
      wek[j].push_back(i);
      juz[i] = 1;
      j++;
    }
  for (i = 0; i < n; i++)
    if (juz[i] == 0) wek[k - 1].push_back(i);
  res = 0;
  for (i = 0; i < k; i++) {
    minn = INF;
    st = 0;
    for (j = 0; j < wek[i].size(); j++) {
      minn = min(minn, c[wek[i][j]]);
      if (t[wek[i][j]] == 1) st = 1;
      res += 2 * c[wek[i][j]];
    }
    if (st == 1) res -= minn;
  }
  cout << res / 2 << ".";
  if (res % 2 == 1)
    printf("5\n");
  else
    printf("0\n");
  for (i = 0; i < k; i++) {
    printf("%d ", wek[i].size());
    for (j = 0; j < wek[i].size(); j++) printf("%d ", wek[i][j] + 1);
    printf("\n");
  }
  return 0;
}
