#include <bits/stdc++.h>
using namespace std;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
struct Node {
  int n, v;
  bool operator<(const Node& a) const { return v < a.v; }
};
long long sum;
double ans;
int l, m, v, t, n, k;
Node a[0X800], b[0X800];
int main() {
  scanf("%d%d", &n, &k);
  l = m = sum = 0;
  for (int i = 0; i < n; ++i) {
    scanf("%d%d", &v, &t);
    sum += v;
    if (t == 1) {
      a[m].v = v;
      a[m++].n = i + 1;
    } else {
      b[l].v = v;
      b[l++].n = i + 1;
    }
  }
  sort(a, a + m);
  sort(b, b + l);
  ans = 0;
  if (m >= k) {
    for (int i = 1; i < k; ++i) ans += a[m - k + i].v / 2.0;
    if (l > 0)
      ans += min(b[0].v, a[0].v) / 2.0;
    else
      ans += a[0].v / 2.0;
    ans = sum - ans;
    printf("%.1f\n", ans);
    printf("%d", n - (k - 1));
    for (int i = 0; i < l; ++i) printf(" %d", b[i].n);
    for (int i = 0; i <= m - k; ++i) printf(" %d", a[i].n);
    printf("\n");
    for (int i = 1; i < k; ++i) printf("1 %d\n", a[m - k + i].n);
  } else {
    for (int i = 0; i < m; ++i) ans += a[i].v / 2.0;
    ans = sum - ans;
    printf("%.1f\n", ans);
    for (int i = 0; i < m; ++i) printf("1 %d\n", a[i].n);
    for (int i = m; i < k - 1; ++i) printf("1 %d\n", b[i - m].n);
    printf("%d", n - k + 1);
    for (int i = k - m - 1; i < l; ++i) printf(" %d", b[i].n);
    printf("\n");
  }
  return 0;
}
