#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:16777216")
using namespace std;
vector<pair<double, int> > pencils;
vector<pair<double, int> > taburets;
vector<int> res[1000];
int main() {
  int N, K;
  cin >> N >> K;
  double sum = 0;
  for (int i = 0; i < N; i++) {
    int t;
    double c;
    cin >> c >> t;
    sum += c;
    if (t == 1)
      taburets.push_back(make_pair(c, i + 1));
    else
      pencils.push_back(make_pair(c, i + 1));
  }
  sort(taburets.begin(), taburets.end());
  sort(pencils.begin(), pencils.end());
  int k = taburets.size(), l = pencils.size();
  int u = min(K - 1, k);
  for (int i = 0; i < u; i++) sum -= taburets[k - i - 1].first / 2;
  double a;
  if (taburets.empty())
    a = pencils[0].first / 2;
  else if (pencils.empty())
    a = taburets[0].first / 2;
  else
    a = min(taburets[0].first, pencils[0].first) / 2;
  if (k >= K) sum -= a;
  printf("%.1lf\n", sum);
  vector<int> por;
  for (int i = 0; i < k; i++) por.push_back(taburets[k - i - 1].second);
  for (int i = 0; i < l; i++) por.push_back(pencils[i].second);
  for (int i = 0; i < K - 1; i++) printf("%d %d\n", 1, por[i]);
  cout << N - K + 1 << " ";
  for (int i = K - 1; i < N - 1; i++) cout << por[i] << " ";
  cout << por[N - 1] << endl;
  return 0;
}
