#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const double EPS = 1e-9;
pair<int, int> T[2000], K[2000];
int cntT = 0, cntK = 0;
vector<int> ans[2000];
int minCost[2000];
bool tab[2000];
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  long long cost = 0;
  for (int i = 0; i < n; ++i) {
    int c, t;
    scanf("%d%d", &c, &t);
    cost += c * 2;
    if (t == 1) {
      T[cntT++] = pair<int, int>(c, i + 1);
    } else {
      K[cntK++] = pair<int, int>(c, i + 1);
    }
  }
  sort(T, T + cntT);
  sort(K, K + cntK);
  reverse(T, T + cntT);
  reverse(K, K + cntK);
  memset(minCost, 0x7f, sizeof(minCost));
  for (int i = 0; i < min(cntT, k); ++i) {
    ans[i].push_back(T[i].second);
    minCost[i] = min(minCost[i], T[i].first);
    tab[i] = true;
  }
  for (int i = min(cntT, k); i < cntT; ++i) {
    ans[k - 1].push_back(T[i].second);
    minCost[k - 1] = min(minCost[k - 1], T[i].first);
    tab[k - 1] = true;
  }
  int pos = 0;
  for (int i = min(cntT, k); i < k; ++i) {
    ans[i].push_back(K[pos].second);
    minCost[i] = min(minCost[i], K[pos].first);
    ++pos;
  }
  while (pos < cntK) {
    ans[k - 1].push_back(K[pos].second);
    minCost[k - 1] = min(minCost[k - 1], K[pos].first);
    ++pos;
  }
  for (int i = 0; i < k; ++i) {
    if (tab[i]) cost -= minCost[i];
  }
  printf("%I64d.%I64d\n", cost / 2, (cost % 2) * 5);
  for (int i = 0; i < k; ++i) {
    printf("%d", ans[i].size());
    for (int j = 0; j < ans[i].size(); ++j) {
      printf(" %d", ans[i][j]);
    }
    puts("");
  }
  return 0;
}
