#include <bits/stdc++.h>
using namespace std;
struct Node {
  int a, id;
  bool operator<(const Node& x) const { return a > x.a; }
} T[1010], S[1010];
double f[1010][1010];
int Can[1010], point[1010];
int n, k, num1, num2;
double ans;
int main() {
  scanf("%d%d", &n, &k);
  int x, y;
  for (int i = 0; i < n; ++i) {
    scanf("%d%d", &x, &y);
    if (y == 1) {
      T[num1].id = i + 1;
      T[num1++].a = x;
    } else {
      S[num2].id = i + 1;
      S[num2++].a = x;
    }
  }
  sort(T, T + num1);
  sort(S, S + num2);
  if (num1 >= k - 1) {
    for (int i = 0; i < k - 1; ++i) ans += (double)(T[i].a) / 2;
    for (int i = k - 1; i < num1; ++i) ans += T[i].a;
    for (int i = 0; i < num2; ++i) ans += S[i].a;
    if (num1 >= k) {
      double Num = T[num1 - 1].a;
      if (num2) Num = ((Num) < (S[num2 - 1].a) ? (Num) : (S[num2 - 1].a));
      ans -= Num / 2;
    }
    printf("%.1f\n", ans);
    for (int i = 0; i < k - 1; ++i) printf("%d %d\n", 1, T[i].id);
    printf("%d ", n - k + 1);
    for (int i = k - 1; i < num1; ++i) printf("%d ", T[i].id);
    for (int i = 0; i < num2; ++i) printf("%d ", S[i].id);
  } else {
    for (int i = 0; i < num1; ++i) ans += (double)(T[i].a) / 2;
    for (int i = 0; i < num2; ++i) ans += S[i].a;
    printf("%.1f", ans);
    for (int i = 0; i < num1; ++i) printf("\n%d %d", 1, T[i].id);
    int j, i;
    for (i = num1, j = 0; i < k - 1; ++i, ++j) printf("\n%d %d", 1, S[j].id);
    printf("\n%d", n - i);
    for (; j < num2; ++j) printf(" %d", S[j].id);
  }
  return 0;
}
