#include <bits/stdc++.h>
using namespace std;
long long price[1020], type[1020];
vector<int> cart[1020];
int main() {
  int K, N;
  while (scanf("%d%d", &N, &K) != EOF) {
    for (int i = 0; i < (int)(1020); ++i) cart[i].clear();
    vector<pair<long long, int> > stool;
    vector<pair<long long, int> > all;
    long long sum = 0;
    for (int i = 0; i < (int)(N); ++i) {
      int p, t;
      scanf("%d%d", &p, &t);
      price[i] = p;
      type[i] = t;
      sum += p;
      if (t == 1) {
        stool.push_back(make_pair(p, i));
      } else {
        all.push_back(make_pair(p, i));
      }
    }
    sort(stool.begin(), stool.end());
    int idx = 0;
    for (; idx < K; ++idx) {
      if ((int)((stool).size()) == 0) break;
      cart[idx].push_back(stool.back().second);
      stool.pop_back();
    }
    for (__typeof((stool).begin()) it = (stool).begin(); it != (stool).end();
         ++it)
      all.push_back(*it);
    sort(all.begin(), all.end());
    long long discount = 0;
    int k = K - 1;
    for (__typeof((all).begin()) it = (all).begin(); it != (all).end(); ++it) {
      long long p = it->first;
      if (k == idx - 1 && (int)((cart[k]).size()) == 1) {
        discount += min(price[cart[k][0]], p);
      }
      cart[k].push_back(it->second);
      if (idx + 1 <= k) {
        k--;
      }
    }
    for (int i = 0; i < (int)(K); ++i)
      if (i < idx && (int)((cart[i]).size()) == 1) {
        discount += price[cart[i][0]];
      }
    double res = sum - 0.5 * discount;
    printf("%.1f\n", res);
    for (int i = 0; i < (int)(K); ++i) {
      printf("%d", (int)((cart[i]).size()));
      for (__typeof((cart[i]).begin()) it = (cart[i]).begin();
           it != (cart[i]).end(); ++it)
        printf(" %d", 1 + *it);
      puts("");
    }
  }
}
