#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
template <class T>
typename T::value_type arr_sum(const T& v, int n) {
  typename T::value_type sum = 0;
  for (int i = (0); i < (n); ++i) sum += v[i];
  return sum;
}
struct Sync_stdio {
  Sync_stdio() {
    cin.tie(NULL);
    ios_base::sync_with_stdio(false);
  }
} _sync_stdio;
int main() {
  int n, k;
  cin >> n >> k;
  vector<pair<int, int> > v;
  vector<pair<int, int> > w;
  long long cost = 0;
  for (int i = (0); i < (n); ++i) {
    int c, t;
    cin >> c >> t;
    cost += c;
    if (t == 2) {
      v.push_back({c, i});
    } else {
      w.push_back({c, i});
    }
  }
  sort(v.begin(), v.end());
  sort(w.begin(), w.end());
  vector<int> res;
  long long sum = 0;
  while (w.size() > 0 && res.size() < k - 1) {
    res.push_back(w.back().second);
    sum += w.back().first;
    w.pop_back();
  }
  reverse(v.begin(), v.end());
  while (v.size() > 0 && res.size() < k - 1) {
    res.push_back(v.back().second);
    v.pop_back();
  }
  reverse(v.begin(), v.end());
  if (w.size() == 0) {
    sum += 0;
  } else if (v.size() == 0) {
    sum += w[0].first;
  } else {
    sum += min(w[0].first, v[0].first);
  }
  sum = 2 * cost - sum;
  cout << sum / 2 << (sum % 2 ? ".5" : ".0") << "\n";
  for (auto i : res) {
    cout << "1 " << i + 1 << "\n";
  }
  cout << v.size() + w.size() << " ";
  for (auto i : w) {
    cout << i.second + 1 << " ";
  }
  for (auto i : v) {
    cout << i.second + 1 << " ";
  }
}
