#include <bits/stdc++.h>
using namespace std;
int main() {
  vector<pair<long long int, long long int> > a[2];
  long long int n, k, c, d;
  double res = 0.0;
  cin >> n >> k;
  for (long long int i = 0; i < ((long long int)(n)); ++i) {
    cin >> c >> d;
    a[d - 1].push_back(make_pair(c, i + 1));
    res += c;
  }
  vector<vector<pair<long long int, long long int> > > ans(k);
  sort((a[0]).begin(), (a[0]).end());
  reverse((a[0]).begin(), (a[0]).end());
  for (long long int index = 0; index < ((long long int)(2)); ++index)
    for (long long int i = 0;
         i < ((long long int)(((long long int)(a[index]).size()))); ++i)
      for (long long int j = 0; j < ((long long int)(k)); ++j) {
        if (((long long int)(ans[j]).size()) && j + 1 != k) continue;
        ans[j].push_back(a[index][i]);
        break;
      }
  for (long long int i = 0; i < ((long long int)(k)); ++i) {
    sort((ans[i]).begin(), (ans[i]).end());
    if (i < ((long long int)(a[0]).size())) res -= ans[i][0].first * 0.5;
  }
  printf("%0.1lf\n", res);
  for (long long int i = 0; i < ((long long int)(k)); ++i) {
    cout << ((long long int)(ans[i]).size()) << " ";
    for (long long int j = 0;
         j < ((long long int)(((long long int)(ans[i]).size()))); ++j)
      cout << ans[i][j].second << " ";
    cout << endl;
  }
}
