#include <bits/stdc++.h>
using namespace std;
const long long N = 1005;
long long n, k;
long long c[N], t[N];
vector<pair<long long, long long> > s, p;
double ans = 0;
bool vis[N];
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> n >> k;
  for (long long i = 1; i <= n; i++) {
    cin >> c[i] >> t[i];
    if (t[i] == 1)
      s.push_back({c[i], i});
    else {
      p.push_back({c[i], i});
      ans += c[i];
    }
  }
  sort(s.rbegin(), s.rend());
  vector<long long> v;
  long long printed = 0;
  for (long long i = 0; i < s.size(); i++) {
    if (i <= k - 2) {
      ans += 0.5 * s[i].first;
      vis[s[i].second] = 1;
    } else
      ans += s[i].first;
  }
  double mn = 1e9;
  for (long long i = 1; i <= n; i++) {
    if (!vis[i]) mn = min(mn, 1.0 * c[i]);
  }
  if (s.size() >= k) ans -= 0.5 * mn;
  cout << fixed << setprecision(1) << ans << "\n";
  for (long long i = 0; i < s.size(); i++) {
    if (i <= k - 2) {
      printed++;
      cout << 1 << " " << s[i].second << "\n";
    }
  }
  vector<long long> rem;
  for (long long i = 1; i <= n; i++) {
    if (!vis[i]) rem.push_back(i);
  }
  while (printed + 1 < k) {
    cout << 1 << " " << rem.back() << "\n";
    rem.pop_back();
    printed++;
  }
  cout << rem.size() << " ";
  for (auto &it : rem) cout << it << " ";
  return 0;
}
