#include <bits/stdc++.h>
using namespace std;
const int maxn = 1050;
vector<pair<int, int> > A, B;
int n, k;
long long ans = 0;
ostream& operator<<(ostream& out, const vector<int>& a) {
  out << a.size();
  for (int i = 0; i < (a.size()); ++i) out << ' ' << a[i];
  out << endl;
  return out;
}
int main(void) {
  cin >> n >> k;
  for (int i = 0; i < (n); ++i) {
    int a, b;
    scanf("%d%d", &a, &b);
    if (b == 1)
      A.push_back(make_pair(a, i + 1));
    else
      B.push_back(make_pair(a, i + 1));
    ans += 2 * a;
  }
  sort(A.begin(), A.end(), greater<pair<int, int> >());
  sort(B.begin(), B.end(), greater<pair<int, int> >());
  ostringstream sout;
  int sa = A.size(), sb = B.size();
  int ca = 0, cb = 0;
  while (k--) {
    vector<int> buf;
    if (!k) {
      int res = 0x7fffffff;
      bool tag = (ca == sa);
      while (ca < sa)
        buf.push_back(A[ca].second), res = min(res, A[ca++].first);
      while (cb < sb)
        buf.push_back(B[cb].second), res = min(res, B[cb++].first);
      if (!tag) ans -= res;
    } else if (ca < sa) {
      buf.push_back(A[ca].second);
      ans -= A[ca++].first;
    } else {
      buf.push_back(B[cb++].second);
    }
    sout << buf;
  }
  printf("%.1lf\n", double(ans) / 2);
  cout << sout.str();
}
