#include <bits/stdc++.h>
using namespace std;
pair<int, int> a[100100];
vector<int> cart[100100];
int id[100100];
int n, K;
double ans;
bool cmp(int x, int y) { return a[x].first < a[y].first; }
int main() {
  scanf("%d%d", &n, &K);
  for (int i = 0; i < n; i++) {
    scanf("%d%d", &a[i].first, &a[i].second);
    id[i] = i;
  }
  sort(id, id + n, cmp);
  int cur = 0;
  for (int i = n - 1; i >= 0; i--)
    if (a[id[i]].second == 1) {
      if (cart[K - 1].size() == 0)
        ans += a[id[i]].first / 2.0;
      else
        ans += a[id[i]].first;
      cart[cur].push_back(id[i]);
      if (cur < K - 1) cur++;
    }
  if (cart[K - 1].size() == 0) {
    for (int i = 0; i < n; i++)
      if (a[id[i]].second == 2) {
        cart[cur].push_back(id[i]);
        if (cur < K - 1) cur++;
        ans += a[id[i]].first;
      }
  } else {
    ans += a[cart[K - 1][0]].first / 2.0;
    for (int i = 0; i < n; i++)
      if (a[id[i]].second == 2) {
        cart[K - 1].push_back(id[i]);
        ans += a[id[i]].first;
      }
    sort(cart[K - 1].begin(), cart[K - 1].end(), cmp);
    ans -= a[cart[K - 1][0]].first / 2.0;
  }
  printf("%0.1lf\n", ans);
  for (int i = 0; i < K; i++) {
    printf("%d ", cart[i].size());
    for (int j = 0; j < cart[i].size(); j++) printf("%d ", cart[i][j] + 1);
    printf("\n");
  }
}
