#include <bits/stdc++.h>
using namespace std;
int cart[3010][3010], n, k;
struct node {
  int id;
  int price;
} stool[3010], pen[3010], a[3010];
bool cmp(node a, node b) { return a.price > b.price; }
int main() {
  int c, t, x, y, z;
  long long sum;
  long long disc;
  int mindisc;
  while (~scanf("%d%d", &n, &k)) {
    x = y = z = 0;
    sum = disc = 0;
    for (int i = 0; i < n; i++) {
      scanf("%d%d", &c, &t);
      sum += c;
      if (t == 1) {
        stool[x].id = i + 1;
        stool[x++].price = c;
      } else {
        pen[y].id = i + 1;
        pen[y++].price = c;
      }
    }
    sort(stool, stool + x, cmp);
    if (x <= k) {
      for (int i = 0; i < x; i++) {
        cart[i][0] = stool[i].id;
        disc += stool[i].price;
        mindisc = stool[i].price;
      }
      for (int i = 0; i < y; i++) {
        if (x + i < k)
          cart[x + i][0] = pen[i].id;
        else {
          a[z].id = pen[i].id;
          a[z++].price = pen[i].price;
        }
      }
    } else {
      for (int i = 0; i < x; i++) {
        if (i < k) {
          cart[i][0] = stool[i].id;
          disc += stool[i].price;
          mindisc = stool[i].price;
        } else {
          a[z].id = stool[i].id;
          a[z++].price = stool[i].price;
        }
      }
      for (int i = 0; i < y; i++) {
        a[z].id = pen[i].id;
        a[z++].price = pen[i].price;
      }
    }
    sort(a, a + z, cmp);
    disc -= mindisc;
    if (x >= k && z > 0) mindisc = min(mindisc, a[z - 1].price);
    disc += mindisc;
    for (int i = 0; i < z; i++) cart[k - 1][1 + i] = a[i].id;
    printf("%.1lf\n", 1.0 * sum - disc / 2.0);
    for (int i = 0; i < k - 1; i++) printf("1 %d\n", cart[i][0]);
    printf("%d", z + 1);
    for (int i = 0; i <= z; i++) printf(" %d", cart[k - 1][i]);
    printf("\n");
  }
  return 0;
}
