#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > tab;
vector<pair<int, int> > kar;
vector<int> res[1010];
int main(int argc, char** argv) {
  int n, k;
  cin >> n >> k;
  int c, t;
  for (int i = 0; i < n; ++i) {
    cin >> c >> t;
    if (t == 1)
      tab.push_back(make_pair(c, i + 1));
    else
      kar.push_back(make_pair(c, i + 1));
  }
  long long ans = 0;
  sort(tab.begin(), tab.end());
  sort(kar.begin(), kar.end());
  int curres = 0;
  for (int i = 0; i < min(k - 1, (int)tab.size()); ++i) {
    ans += ((long long)tab[tab.size() - 1 - i].first);
    res[curres++].push_back(tab[tab.size() - 1 - i].second);
  }
  int lk = ans % 2;
  ans /= 2;
  if (tab.size() >= k) {
    for (int i = 0; i < (tab.size() - k + 1); ++i) {
      ans += tab[i].first;
      res[k - 1].push_back(tab[i].second);
    }
    int v;
    if (kar.size() > 0) {
      if (tab.size() > 0)
        v = min(tab[0].first, kar[0].first);
      else
        v = kar[0].first;
    } else
      v = tab[0].first;
    if (v % 2) {
      if (lk) {
        ++ans;
        lk = 0;
      } else
        lk = 1;
    }
    ans -= (v / 2 + v % 2);
    for (int i = 0; i < kar.size(); ++i) {
      ans += kar[i].first;
      res[k - 1].push_back(kar[i].second);
    }
  } else {
    int tp = 0;
    for (int i = 0; i < k - tab.size() - 1; ++i) {
      res[curres++].push_back(kar[i].second);
      ++tp;
    }
    for (int i = tp; i < kar.size(); ++i) {
      res[k - 1].push_back(kar[i].second);
    }
    for (int i = 0; i < kar.size(); ++i) ans += kar[i].first;
  }
  cout << ans;
  if (lk) {
    cout << ".5" << endl;
  } else
    cout << ".0" << endl;
  for (int i = 0; i < k; ++i) {
    cout << res[i].size() << " ";
    for (int j = 0; j < res[i].size(); ++j) cout << res[i][j] << " ";
    cout << endl;
  }
  return 0;
}
