#include <bits/stdc++.h>
using namespace std;
int n, k;
pair<int, int> ss[1 << 20];
int pi[1 << 20];
int S, P;
int main() {
  cin >> n >> k;
  long double sum = 0;
  int small = 1e9;
  for (int i = 0; i < n; ++i) {
    int c, t;
    cin >> c >> t;
    sum += c;
    if (t == 1)
      ss[S++] = pair<int, int>(c, i + 1);
    else
      pi[P++] = i + 1;
    small = min(small, c);
  }
  sort(ss, ss + S);
  reverse(ss, ss + S);
  for (int i = 0; i < min(k - 1, S); ++i) {
    sum -= .5 * ss[i].first;
  }
  if (k - 1 < S) sum -= .5 * small;
  cout << fixed << setprecision(1) << sum << '\n';
  for (int i = 0; i < k - 1; ++i) {
    if (i < S)
      cout << 1 << ' ' << ss[i].second << '\n';
    else
      cout << 1 << ' ' << pi[--P] << '\n';
  }
  if (k <= S) {
    cout << S + 1 - k + P;
    for (int i = k - 1; i < S; ++i) cout << ' ' << ss[i].second;
  } else {
    cout << P;
  }
  for (int i = 0; i < P; ++i) cout << ' ' << pi[i];
  cout << '\n';
}
