#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, k;
  cin >> n >> k;
  vector<long long> s, p;
  long long t = 0;
  multimap<long long, long long> q;
  long long m = 99999999999999;
  for (long long i = 0; i < n; i++) {
    long long l, r;
    cin >> l >> r;
    m = min(m, l);
    if (r == 1) {
      s.push_back(l);
      q.insert({l, i});
      if (q.size() == k) q.erase(q.begin());
    } else
      p.push_back(l);
    t += l;
  }
  sort(s.begin(), s.end(), greater<long long>());
  long long sub = 0;
  for (long long i = 0; i <= min((long long)s.size() - 1, k - 2); i++)
    sub += s[i];
  if (s.size() >= k) sub += m;
  t -= sub;
  t += sub / 2;
  if (sub % 2)
    cout << t << ".5"
         << "\n";
  else
    cout << t << ".0"
         << "\n";
  set<long long> q1, q2;
  auto it = q.begin();
  while (it != q.end()) {
    q1.insert(it->second);
    it++;
  }
  for (long long i = 0; i < n; i++) {
    if (q1.find(i) == q1.end()) q2.insert(i);
  }
  for (long long i = 0; i < k - 1; i++) {
    if (q1.size() != 0) {
      cout << 1 << " " << *q1.begin() + 1 << "\n";
      q1.erase(q1.begin());
    } else {
      cout << 1 << " " << *q2.begin() + 1 << "\n";
      q2.erase(q2.begin());
    }
  }
  cout << q2.size() << " ";
  while (q2.size()) {
    cout << *q2.begin() + 1 << " ";
    q2.erase(q2.begin());
  }
}
