#include <bits/stdc++.h>
using namespace std;
const int maxn = 100010;
const int inf = 0x3f3f3f3f;
const int modu = 1e9 + 7;
int t, n, m, k, p, q, cnta, cntb;
double sum, res, ans;
struct pen {
  int money;
  int num;
  int pp;
} a[maxn];
vector<int> ve[110];
bool cmp(const pen a, const pen b) {
  return a.pp == b.pp ? a.money > b.money : a.pp < b.pp;
}
int main() {
  cnta = inf;
  sum = 0;
  res = 0;
  sum = 0;
  memset(a, 0, sizeof(a));
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> p >> q;
    cnta = min(cnta, p);
    a[i].money = p;
    a[i].pp = q;
    a[i].num = i + 1;
  }
  sort(a, a + n, cmp);
  int j;
  for (j = 0; j < k - 1 && a[j].pp == 1; j++) {
    sum += a[j].money * 0.5;
  }
  if (a[k - 1].pp == 1) sum -= cnta * 0.5;
  for (j; j < n; j++) {
    sum += a[j].money;
  }
  printf("%.1f\n", sum);
  for (int i = 0; i < k - 1; ++i) {
    printf("1 %d\n", a[i].num);
  }
  cout << n - k + 1;
  for (int i = k - 1; i < n; ++i) {
    printf(" %d", a[i].num);
  }
  cout << endl;
  return 0;
}
