#include <bits/stdc++.h>
using namespace std;
struct tab {
  int c, pl;
};
int ls(tab a, tab b) { return a.c > b.c; }
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> c(n), t(n);
  vector<tab> tabs;
  long long res = 0;
  long long mn = 1000000000;
  for (int i = 0; i < n; i++) {
    cin >> c[i] >> t[i];
    res += c[i];
    mn = min(mn, (long long)c[i]);
    if (t[i] == 1) {
      tab nw;
      nw.c = c[i];
      nw.pl = i;
      tabs.push_back(nw);
    }
  }
  if (tabs.size() < k) mn = 0;
  sort(tabs.begin(), tabs.end(), ls);
  vector<bool> used(n, 0);
  for (int i = 0; i < min(k - 1, (int)tabs.size()); i++) {
    mn += tabs[i].c;
  }
  res -= mn / 2 + mn % 2;
  cout << res;
  if (mn % 2)
    cout << ".5";
  else
    cout << ".0";
  cout << endl;
  for (int i = 0; i < min(k - 1, (int)tabs.size()); i++) {
    cout << "1 " << tabs[i].pl + 1 << endl;
    used[tabs[i].pl] = 1;
  }
  for (int i = 0; i < max(0, k - 1 - (int)tabs.size()); i++) {
    int j = 0;
    for (; used[j]; j++)
      ;
    used[j] = 1;
    cout << "1 " << j + 1 << endl;
  }
  cout << n - k + 1;
  for (int i = 0; i < n; i++)
    if (!used[i]) cout << " " << i + 1;
  cout << endl;
}
