#include <cstdio>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cctype>
#include <cassert>
#include <ctime>
#include <iostream>
#include <utility>
#include <algorithm>
#include <limits>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <list>
#include <queue>
#include <deque>
#include <bitset>
#include <stack>
#include <complex>

#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define fs first
#define sc second
#define sz(x) (int((x).size()))
#define all(x) ((x).begin()),((x).end())
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define fab(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)
#define fba(i,b,a) for(int (i)=(b);(i)>=(a);(i)--)
#define MAX(a,x) a=max(a,x)
#define MIN(a,x) a=min(a,x)

using namespace std;

const double eps = 1e-10, inf = 1e10;
typedef long long ll;

int n, k, type[1010];
vector<int> carr[1010];
vector< pair<int,int> > stool, pencil, input;

int main()
{
#ifndef ONLINE_JUDGE
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
#endif

    scanf("%d%d", &n, &k);
    rep(i, n)
    {
        int c, t;
        scanf("%d%d", &c, &t);
        ((t == 1) ? stool : pencil).pb(mp(c, i));
        input.pb(mp(c, i));
        type[i] = t;
    }

    sort(stool.rbegin(), stool.rend());
    sort(pencil.rbegin(), pencil.rend());
    int i;
    for (i=0; i<k-1 && i<sz(stool); i++) carr[i].pb(stool[i].sc);
    while (i<sz(stool)) carr[k-1].pb(stool[i++].sc);

    for (i=0; i<k-1 && i<sz(pencil); i++) if (carr[i].empty() || pencil[i].fs >= input[carr[i][0]].fs)
    {
        carr[i].pb(pencil[i].sc);
    }
    else carr[k-1].pb(pencil[i].sc);
    while (i<sz(pencil)) carr[k-1].pb(pencil[i++].sc);

    rep(i, k)
    {
        if (carr[i].empty())
        {
            fba(j, i-1, 0) if (sz(carr[j]) > 1 && type[carr[j].back()] == 2)
            {
                carr[i].pb(carr[j].back());
                carr[j].pop_back();
                break;
            }
        }
    }

    double ans = 0;
    rep(i, k-1)
    {
        if (type[carr[i][0]] == 1)
        {
            ans += input[carr[i][0]].fs / 2.0;
        }
        else
        {
            ans += input[carr[i][0]].fs;
        }

        fab(j, 1, sz(carr[i])-1)
            ans += input[carr[i][j]].fs;
    }

    rep(i, sz(carr[k-1])) ans += input[carr[k-1][i]].fs;

    int min_ass = numeric_limits<int>::max(), has = 0;
    rep(j, sz(carr[k-1]))
    {
        if (min_ass > input[carr[k-1][j]].fs)
        {
            if (type[carr[k-1][j]] == 1)
            {
                has = 1;
            }
            min_ass = input[carr[k-1][j]].fs;
        }
        else if (min_ass == input[carr[k-1][j]].fs && !has)
        {
            if (type[carr[k-1][j]] == 1)
            {
                has = 1;
            }
            min_ass = input[carr[k-1][j]].fs;
        }
    }
    if (has) ans -= min_ass / 2.0;
    else ans -= min_ass;

    cout.precision(1);
    cout << fixed << ans << '\n';
    rep(i, k)
    {
        printf("%d", sz(carr[i]));
        rep(j, sz(carr[i])) printf(" %d", carr[i][j]+1);
        printf("\n");
    }

    return 0;
}


#include <cstdio>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cctype>
#include <cassert>
#include <ctime>
#include <iostream>
#include <utility>
#include <algorithm>
#include <limits>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <list>
#include <queue>
#include <deque>
#include <bitset>
#include <stack>
#include <complex>

#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define fs first
#define sc second
#define sz(x) (int((x).size()))
#define all(x) ((x).begin()),((x).end())
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define fab(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)
#define fba(i,b,a) for(int (i)=(b);(i)>=(a);(i)--)
#define MAX(a,x) a=max(a,x)
#define MIN(a,x) a=min(a,x)

using namespace std;

const double eps = 1e-10, inf = 1e10;
typedef long long ll;

int n, k, type[1010];
vector<int> carr[1010];
vector< pair<int,int> > stool, pencil, input;

int main()
{
#ifndef ONLINE_JUDGE
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
#endif

    scanf("%d%d", &n, &k);
    rep(i, n)
    {
        int c, t;
        scanf("%d%d", &c, &t);
        ((t == 1) ? stool : pencil).pb(mp(c, i));
        input.pb(mp(c, i));
        type[i] = t;
    }

    sort(stool.rbegin(), stool.rend());
    sort(pencil.rbegin(), pencil.rend());

    ll ans = 0;
    int i = 0, j = 0, lasthas = 0, minAss = numeric_limits<int>::max();
    while (i < k-1 && i < sz(stool)) ans += stool[i].fs, carr[i].pb(stool[i].sc), i++;
    while (i+j < k-1 && j < sz(pencil)) ans += 2*pencil[j].fs, carr[i+j].pb(pencil[j].sc), j++;
    while (i < sz(stool)) MIN(minAss, stool[i].fs), ans += 2*stool[i].fs, carr[k-1].pb(stool[i].sc), i++, lasthas = 1;
    while (j < sz(pencil)) MIN(minAss, pencil[i].fs), ans += 2*pencil[j].fs, carr[k-1].pb(pencil[j].sc), j++;
    if (lasthas) ans -= minAss;

    cout << (ans/2) << '.' << (ans%2*5) << '\n';
    rep(i, k)
    {
        printf("%d", sz(carr[i]));
        rep(j, sz(carr[i])) printf(" %d", carr[i][j]+1);
        printf("\n");
    }
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
long a[100001],b[100001];
using namespace std;
bool comp(pair<int,int> a, pair<int,int> b)
{
    return a.first<b.first;
};
vector< vector<pair<int,int> > > q(2001);
int main() {
	int w,t,k,n,m,x,y,i,j,c,ns,np,mns,mxs,nc,alls,allc;vector< pair<int,int> > s,p,tst;
	pair<int,int> tt;
	tst.push_back(tt);
    float tc=0;
	cin>>n>>k;mns=1000001;mxs=0;ns=0;alls=0;nc=0;allc=0;
//	for(i=0;i<k;i++){q.push_back(tst);}
	for(i=0;i<n;i++){ cin>>c>>t;
                     if(t==1){s.push_back(make_pair(c,i+1));if(mns>c)mns=c;if(mxs<c)mxs=c;ns++;alls+=c;}
                     else {p.push_back(make_pair(c,i+1));nc++; allc+=c; }
                  //   cout<<"sdasda";
                     }
    sort(s.begin(),s.end(),comp);
	sort(p.begin(),p.end(),comp);
   // for(i=0;i<ns;i++)cout<<s[i].first<<" "<<s[i].second;cout<<endl;
    //for(i=0;i<nc;i++)cout<<p[i].first<<" "<<s[i].second;cout<<endl;
    w=ns-k;tc=0;
	if(ns==0){tc=0;for(i=0;i<k;i++)q[i].push_back(p[i]);for(;i<nc;i++)q[0].push_back(p[i]);}
	else if(ns<k){ for(i=0;i<ns;i++)q[i].push_back(s[i]);x=0;
                   for(j=i;j<k;j++)q[j].push_back(p[x++]);
                   for(i=x;i<nc;i++)q[k-1].push_back(p[i]);tc=alls; }
	else if(ns>=k){ x=w;
                    for(i=0;i<k;i++){//tt=s[w];tst.push_back(tt);q.push_back(tst);w++;
                    q[i].push_back(s[x++]);if(i)tc+=s[x-1].first;}
                     //cout<<"\nvalues are given"<<w<<endl;
                     for(i=0;i<w;i++)q[0].push_back(s[i]);
                     	//for(i=0;i<k;i++){for(j=0;j<q[i].size();j++)cout<<q[i][j].first<<" x";cout<<endl;}
                      //   cout<<tc<<"q was dasda"<<endl;
                     for(i=0;i<nc;i++){ q[0].push_back(p[i]);if(p[i].first<=mns)mns=p[i].first; }
                       tc+=mns;
                   }
    //<<"CORE VALUES are : "<<alls<<" "<<allc<<" "<<tc<<"tc was"<<endl;
	tc=alls+allc-tc/2;
	printf("%.1f\n",tc);
	for(i=0;i<k;i++){ cout<<q[i].size()<<" ";
    for(j=0;j<q[i].size();j++)cout<<q[i][j].second<<" ";cout<<endl;}
//    cin>>i;
	return 0;
}


#include <iostream>
#include<stdio.h>
#include <vector>
#include <algorithm>
#include <set>
long a[100001],b[100001];
using namespace std;
bool comp(pair<int,int> a, pair<int,int> b)
{
    return a.first<b.first;
};
vector< vector<pair<int,int> > > q(1001);
int main() {
	long long w,t,k,n,m,x,y,i,j,c,ns,np,mns,mxs,nc,alls,allc;vector< pair<int,int> > s,p,tst;
	pair<int,int> tt;
	tst.push_back(tt);
    double tc=0;
	cin>>n>>k;mns=1000000001;mxs=0;ns=0;alls=0;nc=0;allc=0;
//	for(i=0;i<k;i++){q.push_back(tst);}
	for(i=0;i<n;i++){ cin>>c>>t;
                     if(t==1){s.push_back(make_pair(c,i+1));if(mns>c)mns=c;if(mxs<c)mxs=c;ns++;alls+=c;}
                     else {p.push_back(make_pair(c,i+1));nc++; allc+=c; }
                  //   cout<<"sdasda";
                     }
    sort(s.begin(),s.end(),comp);
	sort(p.begin(),p.end(),comp);
   // for(i=0;i<ns;i++)cout<<s[i].first<<" "<<s[i].second;cout<<endl;
    //for(i=0;i<nc;i++)cout<<p[i].first<<" "<<s[i].second;cout<<endl;
    w=ns-k;tc=0;
	if(ns==0){tc=0;for(i=0;i<k;i++)q[i].push_back(p[i]);for(;i<nc;i++)q[0].push_back(p[i]);}
	else if(ns<k){ for(i=0;i<ns;i++)q[i].push_back(s[i]);x=0;
                   for(j=i;j<k;j++)q[j].push_back(p[x++]);
                   for(i=x;i<nc;i++)q[k-1].push_back(p[i]);tc=alls; }
	else if(ns>=k){ x=w;
                    for(i=0;i<k;i++){//tt=s[w];tst.push_back(tt);q.push_back(tst);w++;
                    q[i].push_back(s[x++]);if(i)tc+=s[x-1].first;}
                     //cout<<"\nvalues are given"<<w<<endl;
                     for(i=0;i<w;i++)q[0].push_back(s[i]);
                     	//for(i=0;i<k;i++){for(j=0;j<q[i].size();j++)cout<<q[i][j].first<<" x";cout<<endl;}
                      //   cout<<tc<<"q was dasda"<<endl;
                     for(i=0;i<nc;i++){ q[0].push_back(p[i]);if(p[i].first<=mns)mns=p[i].first; }
                       tc+=mns;
                   }
    //<<"CORE VALUES are : "<<alls<<" "<<allc<<" "<<tc<<"tc was"<<endl;
	tc=alls+allc-tc/2;
	printf("%.1f\n",tc);
	for(i=0;i<k;i++){ cout<<q[i].size()<<" ";
    for(j=0;j<q[i].size();j++)cout<<q[i][j].second<<" ";cout<<endl;}
//   cin>>i;
	return 0;
}


#include <iostream>
#include<stdio.h>
#include <vector>
#include <algorithm>
#include <set>
long a[100001],b[100001];
using namespace std;
bool comp(pair<int,int> a, pair<int,int> b)
{
    return a.first<b.first;
};
vector< vector<pair<int,int> > > q(1001);
int main() {
	int w,t,k,n,m,x,y,i,j,c,ns,np,mns,mxs,nc,alls,allc;vector< pair<int,int> > s,p,tst;
	pair<int,int> tt;
	tst.push_back(tt);
    float tc=0;
	cin>>n>>k;mns=1000000001;mxs=0;ns=0;alls=0;nc=0;allc=0;
//	for(i=0;i<k;i++){q.push_back(tst);}
	for(i=0;i<n;i++){ cin>>c>>t;
                     if(t==1){s.push_back(make_pair(c,i+1));if(mns>c)mns=c;if(mxs<c)mxs=c;ns++;alls+=c;}
                     else {p.push_back(make_pair(c,i+1));nc++; allc+=c; }
                  //   cout<<"sdasda";
                     }
    sort(s.begin(),s.end(),comp);
	sort(p.begin(),p.end(),comp);
   // for(i=0;i<ns;i++)cout<<s[i].first<<" "<<s[i].second;cout<<endl;
    //for(i=0;i<nc;i++)cout<<p[i].first<<" "<<s[i].second;cout<<endl;
    w=ns-k;tc=0;
	if(ns==0){tc=0;for(i=0;i<k;i++)q[i].push_back(p[i]);for(;i<nc;i++)q[0].push_back(p[i]);}
	else if(ns<k){ for(i=0;i<ns;i++)q[i].push_back(s[i]);x=0;
                   for(j=i;j<k;j++)q[j].push_back(p[x++]);
                   for(i=x;i<nc;i++)q[k-1].push_back(p[i]);tc=alls; }
	else if(ns>=k){ x=w;
                    for(i=0;i<k;i++){//tt=s[w];tst.push_back(tt);q.push_back(tst);w++;
                    q[i].push_back(s[x++]);if(i)tc+=s[x-1].first;}
                     //cout<<"\nvalues are given"<<w<<endl;
                     for(i=0;i<w;i++)q[0].push_back(s[i]);
                     	//for(i=0;i<k;i++){for(j=0;j<q[i].size();j++)cout<<q[i][j].first<<" x";cout<<endl;}
                      //   cout<<tc<<"q was dasda"<<endl;
                     for(i=0;i<nc;i++){ q[0].push_back(p[i]);if(p[i].first<=mns)mns=p[i].first; }
                       tc+=mns;
                   }
    //<<"CORE VALUES are : "<<alls<<" "<<allc<<" "<<tc<<"tc was"<<endl;
	tc=alls+allc-tc/2;
	printf("%.1f\n",tc);
	for(i=0;i<k;i++){ cout<<q[i].size()<<" ";
    for(j=0;j<q[i].size();j++)cout<<q[i][j].second<<" ";cout<<endl;}
   // cin>>i;
	return 0;
}


#include <iostream>
#include<stdio.h>
#include <vector>
#include <algorithm>
#include <set>
long a[100001],b[100001];
using namespace std;
bool comp(pair<int,int> a, pair<int,int> b)
{
    return a.first<b.first;
};
vector< vector<pair<int,int> > > q(2001);
int main() {
    int w,t,k,n,m,x,y,i,j,c,ns,np,mns,mxs,nc,alls,allc;vector< pair<int,int> > s,p,tst;
    pair<int,int> tt;
    tst.push_back(tt);
    float tc=0;
    cin>>n>>k;mns=1000001;mxs=0;ns=0;alls=0;nc=0;allc=0;
//  for(i=0;i<k;i++){q.push_back(tst);}
    for(i=0;i<n;i++){ cin>>c>>t;
                     if(t==1){s.push_back(make_pair(c,i+1));if(mns>c)mns=c;if(mxs<c)mxs=c;ns++;alls+=c;}
                     else {p.push_back(make_pair(c,i+1));nc++; allc+=c; }
                  //   cout<<"sdasda";
                     }
    sort(s.begin(),s.end(),comp);
    sort(p.begin(),p.end(),comp);
   // for(i=0;i<ns;i++)cout<<s[i].first<<" "<<s[i].second;cout<<endl;
    //for(i=0;i<nc;i++)cout<<p[i].first<<" "<<s[i].second;cout<<endl;
    w=ns-k;tc=0;
    if(ns==0){tc=0;for(i=0;i<k;i++)q[i].push_back(p[i]);for(;i<nc;i++)q[0].push_back(p[i]);}
    else if(ns<k){ for(i=0;i<ns;i++)q[i].push_back(s[i]);x=0;
                   for(j=i;j<k;j++)q[j].push_back(p[x++]);
                   for(i=x;i<nc;i++)q[k-1].push_back(p[i]);tc=alls; }
    else if(ns>=k){ x=w;
                    for(i=0;i<k;i++){//tt=s[w];tst.push_back(tt);q.push_back(tst);w++;
                    q[i].push_back(s[x++]);if(i)tc+=s[x-1].first;}
                     //cout<<"\nvalues are given"<<w<<endl;
                     for(i=0;i<w;i++)q[0].push_back(s[i]);
                        //for(i=0;i<k;i++){for(j=0;j<q[i].size();j++)cout<<q[i][j].first<<" x";cout<<endl;}
                      //   cout<<tc<<"q was dasda"<<endl;
                     for(i=0;i<nc;i++){ q[0].push_back(p[i]);if(p[i].first<=mns)mns=p[i].first; }
                       tc+=mns;
                   }
    //<<"CORE VALUES are : "<<alls<<" "<<allc<<" "<<tc<<"tc was"<<endl;
    tc=alls+allc-tc/2;
    printf("%.1f\n",tc);
    for(i=0;i<k;i++){ cout<<q[i].size()<<" ";
    for(j=0;j<q[i].size();j++)cout<<q[i][j].second<<" ";cout<<endl;}
//    cin>>i;
    return 0;
}


#include <iostream>
#include<stdio.h>
#include <vector>
#include <algorithm>
#include <set>
long a[100001],b[100001];
using namespace std;
bool comp(pair<int,int> a, pair<int,int> b)
{
    return a.first<b.first;
};
vector< vector<pair<int,int> > > q(1001);
int main() {
	int w,t,k,n,m,x,y,i,j,c,ns,np,mns,mxs,nc,alls,allc;vector< pair<int,int> > s,p,tst;
	pair<int,int> tt;
	tst.push_back(tt);
    float tc=0;
	cin>>n>>k;mns=1000000001;mxs=0;ns=0;alls=0;nc=0;allc=0;
//	for(i=0;i<k;i++){q.push_back(tst);}
	for(i=0;i<n;i++){ cin>>c>>t;
                     if(t==1){s.push_back(make_pair(c,i+1));if(mns>c)mns=c;if(mxs<c)mxs=c;ns++;alls+=c;}
                     else {p.push_back(make_pair(c,i+1));nc++; allc+=c; }
                  //   cout<<"sdasda";
                     }
    sort(s.begin(),s.end(),comp);
	sort(p.begin(),p.end(),comp);
   // for(i=0;i<ns;i++)cout<<s[i].first<<" "<<s[i].second;cout<<endl;
    //for(i=0;i<nc;i++)cout<<p[i].first<<" "<<s[i].second;cout<<endl;
    w=ns-k;tc=0;
	if(ns==0){tc=0;for(i=0;i<k;i++)q[i].push_back(p[i]);for(;i<nc;i++)q[0].push_back(p[i]);}
	else if(ns<k){ for(i=0;i<ns;i++)q[i].push_back(s[i]);x=0;
                   for(j=i;j<k;j++)q[j].push_back(p[x++]);
                   for(i=x;i<nc;i++)q[k-1].push_back(p[i]);tc=alls; }
	else if(ns>=k){ x=w;
                    for(i=0;i<k;i++){//tt=s[w];tst.push_back(tt);q.push_back(tst);w++;
                    q[i].push_back(s[x++]);if(i)tc+=s[x-1].first;}
                     //cout<<"\nvalues are given"<<w<<endl;
                     for(i=0;i<w;i++)q[0].push_back(s[i]);
                     	//for(i=0;i<k;i++){for(j=0;j<q[i].size();j++)cout<<q[i][j].first<<" x";cout<<endl;}
                      //   cout<<tc<<"q was dasda"<<endl;
                     for(i=0;i<nc;i++){ q[0].push_back(p[i]);if(p[i].first<=mns)mns=p[i].first; }
                       tc+=mns;
                   }
    //<<"CORE VALUES are : "<<alls<<" "<<allc<<" "<<tc<<"tc was"<<endl;
	tc=alls+allc-tc/2;
	printf("%.1f\n",tc);
	for(i=0;i<k;i++){ cout<<q[i].size()<<" ";
    for(j=0;j<q[i].size();j++)cout<<q[i][j].second<<" ";cout<<endl;}
    cin>>i;
	return 0;
}


# include <cstdio>
# include <cstring>
# include <cstdlib>
# include <iostream>
# include <string>
# include <cmath>
# include <vector>
# include <algorithm>
# define INF 0x7FFFFFFF
# define REP(i,n) for(int i=0;i<n;i++)
# define REP1(i,n) for(int i=1;i<=n;i++)
# define CLR(i,x) memset(i,x,sizeof(i))
# define For(i,a,b) for(int i=a;i<=b;i++)
# define Trv(p,a) for(int p=a;p>=0;p=next[p])
# define vi vector<int>
# define it iterator
# define pb push_back
using namespace std;
typedef long long int64;

void setIO(){
	freopen("in","r",stdin);
//	freopen("out","w",stdout);
}

vi s[1010];
int c[1020],t[1020],vn,o[1010],m[1010];
struct node{
	int pos,v;
} v[1020];
inline bool operator<(node a,node b)	{return a.v>b.v;}
int n,k;
void work(){
	scanf("%d %d",&n,&k);
	double ans=0;
	REP1(i,n){
		scanf("%d %d",c+i,t+i);
		if(t[i]==1){
			v[vn].pos=i;
			v[vn++].v=c[i];
		}
		ans+=c[i];
	}
	sort(v,v+vn);
	REP(i,vn){
		int f=0;
		REP1(j,k){
			if(!o[j]){
				s[j].pb(v[i].pos);
				m[j]=v[i].v;
				o[j]=1;
				f=1;
				break;
			}
		}
		if(!f){
			int minp=0,mv=INF;
			REP1(j,k){
				if(m[j]<mv){
					minp=j;
					mv=m[j];
				}
			}
			s[minp].pb(v[i].pos);
			m[minp]=min(minp,v[i].v);
		}
	}
	REP1(i,n)	if(t[i]==2){
		int f=0;
		REP1(j,k)	if(o[j]==0){
			s[j].pb(i);
			o[j]=-1;
			f=1;
			break;
		}
		if(!f)	REP1(j,k)	if(o[j]==-1){
			s[j].pb(i);
			f=1;
			break;
		}
		if(!f){
			int minp=0,mv=INF;
			REP1(j,k){
				if(m[j]<mv){
					minp=j;
					mv=m[j];
				}
			}
			s[minp].pb(i);
			m[minp]=min(m[minp],c[i]);
		}
	}
	REP1(i,k)	if(o[i]==1)	ans-=double(m[i])/2;
	printf("%.1lf\n",ans);
	REP1(i,k){
		cout<<s[i].size()<<" ";
		sort(s[i].begin(),s[i].end());
		for(vi::it j=s[i].begin();j!=s[i].end();j++){
			cout<<*j<<" ";
		}
		cout<<endl;
	}
}

int main(){
//	setIO();
	work();
	return 0;
}


# include <cstdio>
# include <cstring>
# include <cstdlib>
# include <iostream>
# include <string>
# include <cmath>
# include <vector>
# include <algorithm>
# define INF 0x7FFFFFFF
# define REP(i,n) for(int i=0;i<n;i++)
# define REP1(i,n) for(int i=1;i<=n;i++)
# define CLR(i,x) memset(i,x,sizeof(i))
# define For(i,a,b) for(int i=a;i<=b;i++)
# define Trv(p,a) for(int p=a;p>=0;p=next[p])
# define vi vector<int>
# define it iterator
# define pb push_back
using namespace std;
typedef long long int64;

void setIO(){
	freopen("in","r",stdin);
//	freopen("out","w",stdout);
}

vi s[1010];
int64 c[1020],m[1010];int t[1020],vn,o[1010];
struct node{
	int64 v;int pos;
} v[1020];
inline bool operator<(node a,node b)	{return a.v>b.v;}
int n,k;
void work(){
	scanf("%d %d",&n,&k);
	int64 ans=0;
	REP1(i,n){
		scanf("%I64d %d",c+i,t+i);
		if(t[i]==1){
			v[vn].pos=i;
			v[vn++].v=c[i];
		}
		ans+=c[i];
//		cout<<c[i]<<endl;
	}
	sort(v,v+vn);
	REP(i,vn){
		int f=0;
		REP1(j,k){
			if(!o[j]){
				s[j].pb(v[i].pos);
				m[j]=v[i].v;
				o[j]=1;
				f=1;
				break;
			}
		}
		if(!f){
			int minp=0,mv=INF;
			REP1(j,k){
				if(m[j]<mv){
					minp=j;
					mv=m[j];
				}
			}
			s[minp].pb(v[i].pos);
			m[minp]=min(m[i],v[i].v);
		}
	}
	REP1(i,n)	if(t[i]==2){
		int f=0;
		REP1(j,k)	if(o[j]==0){
			s[j].pb(i);
			o[j]=-1;
			f=1;
			break;
		}
		if(!f)	REP1(j,k)	if(o[j]==-1){
			s[j].pb(i);
			f=1;
			break;
		}
		if(!f){
			int minp=0,mv=INF;
			REP1(j,k){
				if(m[j]<mv){
					minp=j;
					mv=m[j];
				}
			}
			s[minp].pb(i);
			m[minp]=min(m[minp],c[i]);
		}
	}
	int64 x=0;
	REP1(i,k)	if(o[i]==1){
		//cout<<m[i]<<endl;
		x+=m[i];//ans-=double(m[i])/2;
	}
//	cout<<x<<endl;
	if(x&1){
		cout<<ans-x/2-1<<".5"<<endl;
	}else	cout<<ans-x/2<<".0"<<endl;
//	printf("%.1lf\n",ans);
	REP1(i,k){
		cout<<s[i].size()<<" ";
		sort(s[i].begin(),s[i].end());
		for(vi::it j=s[i].begin();j!=s[i].end();j++){
			cout<<*j<<" ";
		}
		cout<<endl;
	}
}

int main(){
//	setIO();
	work();
	return 0;
}


# include <cstdio>
# include <cstring>
# include <cstdlib>
# include <iostream>
# include <string>
# include <cmath>
# include <vector>
# include <algorithm>
# define INF 0x7FFFFFFF
# define REP(i,n) for(int i=0;i<n;i++)
# define REP1(i,n) for(int i=1;i<=n;i++)
# define CLR(i,x) memset(i,x,sizeof(i))
# define For(i,a,b) for(int i=a;i<=b;i++)
# define Trv(p,a) for(int p=a;p>=0;p=next[p])
# define vi vector<int>
# define it iterator
# define pb push_back
using namespace std;
typedef long long int64;

void setIO(){
	freopen("in","r",stdin);
//	freopen("out","w",stdout);
}

vi s[1010];
int64 c[1020],m[1010];int t[1020],vn,o[1010];
struct node{
	int64 v;int pos;
} v[1020];
inline bool operator<(node a,node b)	{return a.v>b.v;}
int n,k;
void work(){
	scanf("%d %d",&n,&k);
	int64 ans=0;
	REP1(i,n){
		scanf("%I64d %d",c+i,t+i);
		if(t[i]==1){
			v[vn].pos=i;
			v[vn++].v=c[i];
		}
		ans+=c[i];
//		cout<<c[i]<<endl;
	}
	sort(v,v+vn);
	REP(i,vn){
		int f=0;
		REP1(j,k){
			if(!o[j]){
				s[j].pb(v[i].pos);
				m[j]=v[i].v;
				o[j]=1;
				f=1;
				break;
			}
		}
		if(!f){
			int minp=0,mv=INF;
			REP1(j,k){
				if(m[j]<mv){
					minp=j;
					mv=m[j];
				}
			}
			s[minp].pb(v[i].pos);
			m[minp]=min(m[minp],v[i].v);
		}
	}
	REP1(i,n)	if(t[i]==2){
		int f=0;
		REP1(j,k)	if(o[j]==0){
			s[j].pb(i);
			o[j]=-1;
			f=1;
			break;
		}
		if(!f)	REP1(j,k)	if(o[j]==-1){
			s[j].pb(i);
			f=1;
			break;
		}
		if(!f){
			int minp=0,mv=INF;
			REP1(j,k){
				if(m[j]<mv){
					minp=j;
					mv=m[j];
				}
			}
			s[minp].pb(i);
			m[minp]=min(m[minp],c[i]);
		}
	}
	int64 x=0;
	REP1(i,k)	if(o[i]==1){
		//cout<<m[i]<<endl;
		x+=m[i];//ans-=double(m[i])/2;
	}
//	cout<<x<<endl;
	if(x&1){
		cout<<ans-x/2-1<<".5"<<endl;
	}else	cout<<ans-x/2<<".0"<<endl;
//	printf("%.1lf\n",ans);
	REP1(i,k){
		cout<<s[i].size()<<" ";
		sort(s[i].begin(),s[i].end());
		for(vi::it j=s[i].begin();j!=s[i].end();j++){
			cout<<*j<<" ";
		}
		cout<<endl;
	}
}

int main(){
//	setIO();
	work();
	return 0;
}


# include <cstdio>
# include <cstring>
# include <cstdlib>
# include <iostream>
# include <string>
# include <cmath>
# include <vector>
# include <algorithm>
# define INF 0x7FFFFFFF
# define REP(i,n) for(int i=0;i<n;i++)
# define REP1(i,n) for(int i=1;i<=n;i++)
# define CLR(i,x) memset(i,x,sizeof(i))
# define For(i,a,b) for(int i=a;i<=b;i++)
# define Trv(p,a) for(int p=a;p>=0;p=next[p])
# define vi vector<int>
# define it iterator
# define pb push_back
using namespace std;
typedef long long int64;

void setIO(){
	freopen("in","r",stdin);
//	freopen("out","w",stdout);
}

vi s[1010];
int c[1020],t[1020],vn,o[1010],m[1010];
struct node{
	int pos,v;
} v[1020];
inline bool operator<(node a,node b)	{return a.v>b.v;}
int n,k;
void work(){
	scanf("%d %d",&n,&k);
	int64 ans=0;
	REP1(i,n){
		scanf("%d %d",c+i,t+i);
		if(t[i]==1){
			v[vn].pos=i;
			v[vn++].v=c[i];
		}
		ans+=c[i];
	}
	sort(v,v+vn);
	REP(i,vn){
		int f=0;
		REP1(j,k){
			if(!o[j]){
				s[j].pb(v[i].pos);
				m[j]=v[i].v;
				o[j]=1;
				f=1;
				break;
			}
		}
		if(!f){
			int minp=0,mv=INF;
			REP1(j,k){
				if(m[j]<mv){
					minp=j;
					mv=m[j];
				}
			}
			s[minp].pb(v[i].pos);
			m[minp]=min(minp,v[i].v);
		}
	}
	REP1(i,n)	if(t[i]==2){
		int f=0;
		REP1(j,k)	if(o[j]==0){
			s[j].pb(i);
			o[j]=-1;
			f=1;
			break;
		}
		if(!f)	REP1(j,k)	if(o[j]==-1){
			s[j].pb(i);
			f=1;
			break;
		}
		if(!f){
			int minp=0,mv=INF;
			REP1(j,k){
				if(m[j]<mv){
					minp=j;
					mv=m[j];
				}
			}
			s[minp].pb(i);
			m[minp]=min(m[minp],c[i]);
		}
	}
	int64 x=0;
	REP1(i,k)	if(o[i]==1)	x+=m[i];//ans-=double(m[i])/2;
//	cout<<x<<endl;
	if(x&1){
		cout<<ans-x/2-1<<".5"<<endl;
	}else	cout<<ans-x/2<<".0"<<endl;
//	printf("%.1lf\n",ans);
	REP1(i,k){
		cout<<s[i].size()<<" ";
		sort(s[i].begin(),s[i].end());
		for(vi::it j=s[i].begin();j!=s[i].end();j++){
			cout<<*j<<" ";
		}
		cout<<endl;
	}
}

int main(){
//	setIO();
	work();
	return 0;
}


# include <cstdio>
# include <cstring>
# include <cstdlib>
# include <iostream>
# include <string>
# include <cmath>
# include <vector>
# include <algorithm>
# define INF 0x7FFFFFFF
# define REP(i,n) for(int i=0;i<n;i++)
# define REP1(i,n) for(int i=1;i<=n;i++)
# define CLR(i,x) memset(i,x,sizeof(i))
# define For(i,a,b) for(int i=a;i<=b;i++)
# define Trv(p,a) for(int p=a;p>=0;p=next[p])
# define vi vector<int>
# define it iterator
# define pb push_back
using namespace std;
typedef long long int64;

void setIO(){
	freopen("in","r",stdin);
//	freopen("out","w",stdout);
}

vi s[1010];
int c[1020],t[1020],vn,o[1010],m[1010];
struct node{
	int pos,v;
} v[1020];
inline bool operator<(node a,node b)	{return a.v>b.v;}
int n,k;
void work(){
	scanf("%d %d",&n,&k);
	int64 ans=0;
	REP1(i,n){
		scanf("%d %d",c+i,t+i);
		if(t[i]==1){
			v[vn].pos=i;
			v[vn++].v=c[i];
		}
		ans+=c[i];
	}
	sort(v,v+vn);
	REP(i,vn){
		int f=0;
		REP1(j,k){
			if(!o[j]){
				s[j].pb(v[i].pos);
				m[j]=v[i].v;
				o[j]=1;
				f=1;
				break;
			}
		}
		if(!f){
			int minp=0,mv=INF;
			REP1(j,k){
				if(m[j]<mv){
					minp=j;
					mv=m[j];
				}
			}
			s[minp].pb(v[i].pos);
			m[minp]=min(minp,v[i].v);
		}
	}
	REP1(i,n)	if(t[i]==2){
		int f=0;
		REP1(j,k)	if(o[j]==0){
			s[j].pb(i);
			o[j]=-1;
			f=1;
			break;
		}
		if(!f)	REP1(j,k)	if(o[j]==-1){
			s[j].pb(i);
			f=1;
			break;
		}
		if(!f){
			int minp=0,mv=INF;
			REP1(j,k){
				if(m[j]<mv){
					minp=j;
					mv=m[j];
				}
			}
			s[minp].pb(i);
			m[minp]=min(m[minp],c[i]);
		}
	}
	int64 x=0;
	REP1(i,k)	if(o[i]==1)	x+=m[i];//ans-=double(m[i])/2;
//	cout<<x<<endl;
	if(x&1){
		cout<<ans-x/2-1<<".5"<<endl;
	}else	cout<<ans-x/2<<".0"<<endl;
//	printf("%.1lf\n",ans);
	REP1(i,k){
		cout<<s[i].size()<<" ";
		sort(s[i].begin(),s[i].end());
		for(vi::it j=s[i].begin();j!=s[i].end();j++){
			cout<<*j<<" ";
		}
		cout<<endl;
	}
}

int main(){
	setIO();
	work();
	return 0;
}


#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <string>
#include <math.h>

using namespace std;

int const size = 1000 + 5;

pair <int, int> tab[size], pan[size];
//vector <pair <int, int>> ans[size];
//pair <pair <int, int>> tov[size];

int main()
{
    int n, i, j, k, m, hor = 0, c, t, kt, kp;
    long long sum = 0;

    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);

    scanf("%d %d", &n, &k);
    kt = kp = 0;
	for (i = 0; i < n; i++)
	{
		scanf("%d %d", &c, &t);
		if (t == 1)
		{
			tab[kt].first = 2 * c;
			tab[kt++].second = i + 1;
		}
		else
		{
			pan[kp].first = 2 * c;
			pan[kp++].second = i + 1;
		}
	}
	sort(tab, tab + kt);
	sort(pan, pan + kp);
	if (kt < k)
	{
		for (i = 0; i < kt; i++)
			sum += tab[i].first / 2;
		for (i = 0; i < kp; i++)
			sum += pan[i].first;
		if (sum % 2 == 0)
			printf("%I64d.0\n", sum / 2);
		else
			printf("%I64d.5\n", sum / 2);
		for (i = 0; i < kt; i++)
			printf("1 %d\n", tab[i].second);
		for (i = 0; i < k - 1 - kt; i++)
			printf("1 %d\n", pan[i].second);
		printf("%d ", kp - (k - 1 - kt));
		for (i = k - 1 - kt; i < kp; i++)
			printf("%d%c", pan[i].second, " \n"[i == kp - 1]);
	}
	else
	{
		for (i = 0; i < k - 1; i++)
			sum += tab[kt - 1 - i].first / 2;
		for (i = k - 1; i < kt; i++)
			sum += tab[kt - 1 - i].first;
		for (i = 0; i < kp; i++)
			sum += pan[i].first;
		sum -= min(pan[0].first, tab[0].first) / 2;
		if (sum % 2 == 0)
			printf("%I64d.0\n", sum / 2);
		else
			printf("%I64d.5\n", sum / 2);
		for (i = 0; i < k - 1; i++)
			printf("1 %d\n", tab[kt - 1 - i].second);
		printf("%d ", n - k + 1);
		for (i = k - 1; i < kt; i++)
			printf("%d%c", tab[k - 1 - i].second, " \n"[i == n - 1]);
		for (i = 0; i < kp; i++)
			printf("%d%c", pan[i].second, " \n"[i == kp - 1]);
	}

    return 0;
}


#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <string>
#include <math.h>

using namespace std;

int const size = 1000 + 5;

pair <int, int> tab[size], pan[size];
//vector <pair <int, int>> ans[size];
//pair <pair <int, int>> tov[size];

int main()
{
    int n, i, j, k, m, hor = 0, c, t, kt, kp;
    long long sum = 0;

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    scanf("%d %d", &n, &k);
    kt = kp = 0;
	for (i = 0; i < n; i++)
	{
		scanf("%d %d", &c, &t);
		if (t == 1)
		{
			tab[kt].first = 2 * c;
			tab[kt++].second = i + 1;
		}
		else
		{
			pan[kp].first = 2 * c;
			pan[kp++].second = i + 1;
		}
	}
	sort(tab, tab + kt);
	sort(pan, pan + kp);
	if (kt < k)
	{
		for (i = 0; i < kt; i++)
			sum += tab[i].first / 2;
		for (i = 0; i < kp; i++)
			sum += pan[i].first;
		if (sum % 2 == 0)
			printf("%I64d.0\n", sum / 2);
		else
			printf("%I64d.5\n", sum / 2);
		for (i = 0; i < kt; i++)
			printf("1 %d\n", tab[i].second);
		for (i = 0; i < k - 1 - kt; i++)
			printf("1 %d\n", pan[i].second);
		printf("%d ", kp - (k - 1 - kt));
		for (i = k - 1 - kt; i < kp; i++)
			printf("%d%c", pan[i].second, " \n"[i == kp - 1]);
	}
	else
	{
		for (i = 0; i < k - 1; i++)
			sum += tab[kt - 1 - i].first / 2;
		for (i = k - 1; i < kt; i++)
			sum += tab[kt - 1 - i].first;
		for (i = 0; i < kp; i++)
			sum += pan[i].first;
		sum -= min(pan[0].first, tab[0].first) / 2;
		if (sum % 2 == 0)
			printf("%I64d.0\n", sum / 2);
		else
			printf("%I64d.5\n", sum / 2);
		for (i = 0; i < k - 1; i++)
			printf("1 %d\n", tab[kt - 1 - i].second);
		printf("%d ", n - k + 1);
		for (i = k - 1; i < kt; i++)
			printf("%d%c", tab[kt - 1 - i].second, " \n"[i == n - 1]);
		for (i = 0; i < kp; i++)
			printf("%d%c", pan[i].second, " \n"[i == kp - 1]);
	}

    return 0;
}


#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <string>
#include <math.h>

using namespace std;

int const size = 1000 + 5;

pair <int, int> tab[size], pan[size];
//vector <pair <int, int>> ans[size];
//pair <pair <int, int>> tov[size];

int main()
{
    int n, i, j, k, m, hor = 0, c, t, kt, kp;
    long long sum = 0;

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    scanf("%d %d", &n, &k);
    kt = kp = 0;
	for (i = 0; i < n; i++)
	{
		scanf("%d %d", &c, &t);
		if (t == 1)
		{
			tab[kt].first = 2 * c;
			tab[kt++].second = i + 1;
		}
		else
		{
			pan[kp].first = 2 * c;
			pan[kp++].second = i + 1;
		}
	}
	sort(tab, tab + kt);
	sort(pan, pan + kp);
	if (kt < k)
	{
		for (i = 0; i < kt; i++)
			sum += tab[i].first / 2;
		for (i = 0; i < kp; i++)
			sum += pan[i].first;
		if (sum % 2 == 0)
			printf("%I64d.0\n", sum / 2);
		else
			printf("%I64d.5\n", sum / 2);
		for (i = 0; i < kt; i++)
			printf("1 %d\n", tab[i].second);
		for (i = 0; i < k - 1 - kt; i++)
			printf("1 %d\n", pan[i].second);
		printf("%d ", kp - (k - 1 - kt));
		for (i = k - 1 - kt; i < kp; i++)
			printf("%d%c", pan[i].second, " \n"[i == kp - 1]);
	}
	else
	{
		for (i = 0; i < k - 1; i++)
			sum += tab[kt - 1 - i].first / 2;
		for (i = k - 1; i < kt; i++)
			sum += tab[kt - 1 - i].first;
		for (i = 0; i < kp; i++)
			sum += pan[i].first;
		if (kt == 0)
			tab[0].first = 2 * 1000 * 1000 * 1000 + 1;
		if (kp == 0)
			pan[0].first = 2 * 1000 * 1000 * 1000 + 1;
		sum -= min(pan[0].first, tab[0].first) / 2;
		if (sum % 2 == 0)
			printf("%I64d.0\n", sum / 2);
		else
			printf("%I64d.5\n", sum / 2);
		for (i = 0; i < k - 1; i++)
			printf("1 %d\n", tab[kt - 1 - i].second);
		printf("%d ", n - k + 1);
		for (i = k - 1; i < kt; i++)
			printf("%d%c", tab[kt - 1 - i].second, " \n"[i == n - 1]);
		for (i = 0; i < kp; i++)
			printf("%d%c", pan[i].second, " \n"[i == kp - 1]);
	}

    return 0;
}


#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <string>
#include <math.h>

using namespace std;

int const size = 1000 + 5;

pair <int, int> tab[size], pan[size];
//vector <pair <int, int>> ans[size];
//pair <pair <int, int>> tov[size];

int main()
{
    int n, i, j, k, m, hor = 0, c, t, kt, kp;
    long long sum = 0;

    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);

    scanf("%d %d", &n, &k);
    kt = kp = 0;
	for (i = 0; i < n; i++)
	{
		scanf("%d %d", &c, &t);
		if (t == 1)
		{
			tab[kt].first = 2 * c;
			tab[kt++].second = i + 1;
		}
		else
		{
			pan[kp].first = 2 * c;
			pan[kp++].second = i + 1;
		}
	}
	sort(tab, tab + kt);
	sort(pan, pan + kp);
	if (kt < k)
	{
		for (i = 0; i < kt; i++)
			sum += tab[i].first / 2;
		for (i = 0; i < kp; i++)
			sum += pan[i].first;
		if (sum % 2 == 0)
			printf("%I64d.0\n", sum / 2);
		else
			printf("%I64d.5\n", sum / 2);
		for (i = 0; i < kt; i++)
			printf("1 %d\n", tab[i].second);
		for (i = 0; i < k - 1 - kt; i++)
			printf("1 %d\n", pan[i].second);
		printf("%d ", kp - (k - 1 - kt));
		for (i = k - 1 - kt; i < kp; i++)
			printf("%d%c", pan[i].second, " \n"[i == kp - 1]);
	}
	else
	{
		for (i = 0; i < k - 1; i++)
			sum += tab[kt - 1 - i].first / 2;
		for (i = k - 1; i < kt; i++)
			sum += tab[kt - 1 - i].first;
		for (i = 0; i < kp; i++)
			sum += pan[i].first;
		if (kt == 0)
			tab[0].first = 2 * 1000 * 1000 * 1000 + 1;
		if (kp == 0)
			pan[0].first = 2 * 1000 * 1000 * 1000 + 1;
		sum -= min(pan[0].first, tab[0].first) / 2;
		if (sum % 2 == 0)
			printf("%I64d.0\n", sum / 2);
		else
			printf("%I64d.5\n", sum / 2);
		for (i = 0; i < k - 1; i++)
			printf("1 %d\n", tab[kt - 1 - i].second);
		printf("%d ", n - k + 1);
		for (i = k - 1; i < kt; i++)
			printf("%d%c", tab[kt - 1 - i].second, " \n"[i == n - 1]);
		for (i = 0; i < kp; i++)
			printf("%d%c", pan[i].second, " \n"[i == kp - 1]);
	}

    return 0;
}


#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <string>
#include <math.h>

using namespace std;

int const size = 1000 + 5;

pair <int, int> tab[size], pan[size];
//vector <pair <int, int>> ans[size];
//pair <pair <int, int>> tov[size];

int main()
{
    int n, i, j, k, m, hor = 0, c, t, kt, kp;
    long long sum = 0;

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    scanf("%d %d", &n, &k);
    kt = kp = 0;
	for (i = 0; i < n; i++)
	{
		scanf("%d %d", &c, &t);
		if (t == 1)
		{
			tab[kt].first = 2 * c;
			tab[kt++].second = i + 1;
		}
		else
		{
			pan[kp].first = 2 * c;
			pan[kp++].second = i + 1;
		}
	}
	sort(tab, tab + kt);
	sort(pan, pan + kp);
	if (kt < k)
	{
		for (i = 0; i < kt; i++)
			sum += tab[i].first / 2;
		for (i = 0; i < kp; i++)
			sum += pan[i].first;
		if (sum % 2 == 0)
			printf("%I64d.0\n", sum / 2);
		else
			printf("%I64d.5\n", sum / 2);
		for (i = 0; i < kt; i++)
			printf("1 %d\n", tab[i].second);
		for (i = 0; i < k - 1 - kt; i++)
			printf("1 %d\n", pan[i].second);
		printf("%d ", kp - (k - 1 - kt));
		for (i = k - 1 - kt; i < kp; i++)
			printf("%d%c", pan[i].second, " \n"[i == kp - 1]);
	}
	else
	{
		for (i = 0; i < k - 1; i++)
			sum += tab[kt - 1 - i].first / 2;
		for (i = k - 1; i < kt; i++)
			sum += tab[kt - 1 - i].first;
		for (i = 0; i < kp; i++)
			sum += pan[i].first;
		sum -= min(pan[0].first, tab[0].first) / 2;
		if (sum % 2 == 0)
			printf("%I64d.0\n", sum / 2);
		else
			printf("%I64d.5\n", sum / 2);
		for (i = 0; i < k - 1; i++)
			printf("1 %d\n", tab[kt - 1 - i].second);
		printf("%d ", n - k + 1);
		for (i = k - 1; i < kt; i++)
			printf("%d%c", tab[k - 1 - i].second, " \n"[i == n - 1]);
		for (i = 0; i < kp; i++)
			printf("%d%c", pan[i].second, " \n"[i == kp - 1]);
	}

    return 0;
}


#include <cstdio>
#include <vector>
#include <algorithm>

struct penstool{long order, price, kind;};
bool compenstool(penstool A, penstool B){
    if(A.kind == B.kind){return A.price > B.price;}
    else if(A.kind == 1){return 1;}
    else if(B.kind == 1){return 0;}
    return 0;
}

int main(){

    long n(0), k(0); scanf("%ld %ld\n", &n, &k);
    std::vector<penstool> itemVec(n + 1);

    long cheapest(0), minPrice(1e9);
    for(int p = 1; p <= n; p++){
        itemVec[p].order = p;
        scanf("%ld %ld\n", &itemVec[p].price, &itemVec[p].kind);
        if(itemVec[p].price < minPrice){minPrice = itemVec[p].price; cheapest = p;}
    }

    sort(++itemVec.begin(), itemVec.end(), compenstool);

    double totalPrice = 0;
    for(long p = 1; p <= n; p++){
        if((itemVec[p].kind == 1 && p < k) || (itemVec[p].order == cheapest && itemVec[k].kind == 1)){totalPrice += 0.5 * itemVec[p].price;}
        else{totalPrice += itemVec[p].price;}
    }

    printf("%.1lf\n", totalPrice);
    for(long p = 1; p < k; p++){printf("1 %ld\n", itemVec[p].order);}
    printf("%ld ", n - k + 1); for(long p = k; p <= n; p++){printf("%ld ", itemVec[p].order);}
    puts("");

    return 0;
}


#include <cstdio>
#include <vector>
#include <algorithm>

struct penstool{long order, price, kind;};
bool compenstool(penstool A, penstool B){
    if(A.kind == B.kind){return A.price > B.price;}
    else if(A.kind == 1){return 1;}
    else if(B.kind == 1){return 0;}
    return 0;
}

int main(){

    long n(0), k(0); scanf("%ld %ld\n", &n, &k);
    std::vector<penstool> itemVec(n + 1);

    long minPrice(1e9);
    for(int p = 1; p <= n; p++){
        itemVec[p].order = p;
        scanf("%ld %ld\n", &itemVec[p].price, &itemVec[p].kind);
        if(itemVec[p].price < minPrice){minPrice = itemVec[p].price;}
    }

    sort(++itemVec.begin(), itemVec.end(), compenstool);

    double totalPrice = 0;
    for(long p = 1; p <= n; p++){
        if(itemVec[p].kind == 1 && p < k){totalPrice += 0.5 * itemVec[p].price;}
        else{totalPrice += itemVec[p].price;}
    }
    if(itemVec[k].kind == 1){totalPrice -= 0.5 * minPrice;}

    printf("%.1lf\n", totalPrice);
    for(long p = 1; p < k; p++){printf("1 %ld\n", itemVec[p].order);}
    printf("%ld ", n - k + 1); for(long p = k; p <= n; p++){printf("%ld ", itemVec[p].order);}
    puts("");

    return 0;
}


#include <cstdio>
#include <vector>
#include <algorithm>

struct penstool{long order, price, kind;};
bool compenstool(penstool A, penstool B){
    if(A.kind == B.kind){return A.price > B.price;}
    else if(A.kind == 1){return 1;}
    else if(B.kind == 1){return 0;}
    return 0;
}

int main(){

    long n(0), k(0); scanf("%ld %ld\n", &n, &k);
    std::vector<penstool> itemVec(n + 1);

    for(int p = 1; p <= n; p++){
        itemVec[p].order = p;
        scanf("%ld %ld\n", &itemVec[p].price, &itemVec[p].kind);
    }

    sort(++itemVec.begin(), itemVec.end(), compenstool);

    double totalPrice = 0;
    for(long p = 1; p <= n; p++){
        if((itemVec[p].kind == 1 && p < k) || (p == n && itemVec[k].kind == 1)){totalPrice += 0.5 * itemVec[p].price;}
        else{totalPrice += itemVec[p].price;}
    }
    if(itemVec[k].price < itemVec[n].price){totalPrice += 0.5 * (itemVec[n].price - itemVec[k].price);}

    printf("%.1lf\n", totalPrice);
    for(long p = 1; p < k; p++){printf("%ld %ld\n", p, itemVec[p].order);}
    printf("%ld ", k); for(long p = k; p <= n; p++){printf("%ld ", itemVec[p].order);}
    puts("");

    return 0;
}


#include <cstdio>
#include <vector>
#include <algorithm>

struct penstool{long order, price, kind;};
bool compenstool(penstool A, penstool B){
    if(A.kind == B.kind){return A.price > B.price;}
    else if(A.kind == 1){return 1;}
    else if(B.kind == 1){return 0;}
    return 0;
}

int main(){

    long n(0), k(0); scanf("%ld %ld\n", &n, &k);
    std::vector<penstool> itemVec(n + 1);

    for(int p = 1; p <= n; p++){
        itemVec[p].order = p;
        scanf("%ld %ld\n", &itemVec[p].price, &itemVec[p].kind);
    }

    sort(++itemVec.begin(), itemVec.end(), compenstool);

    double totalPrice = 0;
    for(long p = 1; p <= n; p++){
        if((itemVec[p].kind == 1 && p < k) || (p == n && itemVec[k].kind == 1)){totalPrice += 0.5 * itemVec[p].price;}
        else{totalPrice += itemVec[p].price;}
    }
    if(itemVec[k].price < itemVec[n].price){totalPrice += 0.5 * (itemVec[n].price - itemVec[k].price);}

    printf("%.1lf\n", totalPrice);
    for(long p = 1; p < k; p++){printf("%ld %ld\n", p, itemVec[p].order);}
    printf("%ld ", k); for(long p = k; p <= n; p++){printf("%ld ", itemVec[p].order);}

    return 0;
}


#include <cstdio>
#include <vector>
#include <algorithm>

struct penstool{long order, price, kind;};
bool compenstool(penstool A, penstool B){
    if(A.kind == B.kind){return A.price > B.price;}
    else if(A.kind == 1){return 1;}
    else if(B.kind == 1){return 0;}
    return 0;
}

int main(){

    long n(0), k(0); scanf("%ld %ld\n", &n, &k);
    std::vector<penstool> itemVec(n + 1);

    for(int p = 1; p <= n; p++){
        itemVec[p].order = p;
        scanf("%ld %ld\n", &itemVec[p].price, &itemVec[p].kind);
    }

    sort(++itemVec.begin(), itemVec.end(), compenstool);

    double totalPrice = 0;
    for(long p = 1; p <= n; p++){
        if((itemVec[p].kind == 1 && p < k) || (p == n && itemVec[k].kind == 1)){totalPrice += 0.5 * itemVec[p].price;}
        else{totalPrice += itemVec[p].price;}
    }
    if(itemVec[k].price < itemVec[n].price){totalPrice += 0.5 * (itemVec[n].price - itemVec[k].price);}

    printf("%.1lf\n", totalPrice);
    for(long p = 1; p < k; p++){printf("1 %ld\n", itemVec[p].order);}
    printf("%ld ", n - k + 1); for(long p = k; p <= n; p++){printf("%ld ", itemVec[p].order);}
    puts("");

    return 0;
}


//============================================================================
// Name        : Discounts.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<stdio.h>
#include<utility>
#define min(x,y) ((x)<(y)?(x):(y))
using namespace std;
struct Node {
    int value;
    int id;
};
vector<int> out[1000];
vector<struct Node> ak, bk;
bool cmp(struct Node a, struct Node b) {
    return a.value > b.value;
}
int main() {
    //cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!
    int n, k;
    scanf(" %d %d", &n, &k);
    int i, j;
    double ans = 0;
    for (i = 0; i < n; i++) {
        int a, b;

        scanf(" %d %d", &a, &b);
        struct Node temp;
        temp.value = a;
        temp.id = i + 1;
        if (b & 1) {
            ak.push_back(temp);
        } else
            bk.push_back(temp);
        ans += a;
    }
    sort(ak.begin(), ak.end(), cmp);
    sort(bk.begin(), bk.end(), cmp);
    //printf("ans:%.3lf\n",ans);
    for (i = 0; i < k && i < ak.size(); i++) {
        out[i].push_back(ak[i].id);
        ans -= ak[i].value * .5;
    }
    if (ak.size() >= k && bk.size()) {
        ans += ak[k - 1].value*.5;
        ans -= min(ak[ak.size() - 1].value * .5, bk[bk.size() - 1].value * .5);
        for (i = 0; i < bk.size(); i++) {
            out[k - 1].push_back(bk[i].id);
        }
    } else if (ak.size() < k) {
        for (j = 0; i < k; i++, j++) {
            out[i].push_back(bk[j].id);
        }
        while (j < k) {
            out[k - 1].push_back(bk[j++].id);
        }
    }
    printf("%.1lf\n", ans);
    for (i = 0; i < k; i++) {
        printf("%d", out[i].size());
        for (j = 0; j < out[i].size(); j++) {
            printf(" %d", out[i][j]);
        }
        puts("");
    }
    return 0;
}


//============================================================================
// Name        : Discounts.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<stdio.h>
#include<utility>
#define min(x,y) ((x)<(y)?(x):(y))
using namespace std;
struct Node {
    int value;
    int id;
};
vector<int> out[1000];
vector<struct Node> ak, bk;
bool cmp(struct Node a, struct Node b) {
    return a.value > b.value;
}
int main() {
    //cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!
    int n, k;
    scanf(" %d %d", &n, &k);
    int i, j;
    double ans = 0;
    for (i = 0; i < n; i++) {
        int a, b;

        scanf(" %d %d", &a, &b);
        struct Node temp;
        temp.value = a;
        temp.id = i + 1;
        if (b & 1) {
            ak.push_back(temp);
        } else
            bk.push_back(temp);
        ans += a;
    }
    sort(ak.begin(), ak.end(), cmp);
    sort(bk.begin(), bk.end(), cmp);
    //printf("ans:%.3lf\n",ans);
    for (i = 0; i < k && i < ak.size(); i++) {
        out[i].push_back(ak[i].id);
        ans -= ak[i].value * .5;
    }
    if (ak.size() >= k && bk.size()) {
        ans += ak[k - 1].value*.5;
        ans -= min(ak[ak.size() - 1].value * .5, bk[bk.size() - 1].value * .5);
        for (i = 0; i < bk.size(); i++) {
            out[k - 1].push_back(bk[i].id);
        }
    } else if (ak.size() < k) {
        for (j = 0; i < k; i++, j++) {
            out[i].push_back(bk[j].id);
        }
        while (j < bk.size()) {
            out[k - 1].push_back(bk[j++].id);
        }
    }
    printf("%.1lf\n", ans);
    for (i = 0; i < k; i++) {
        printf("%d", out[i].size());
        for (j = 0; j < out[i].size(); j++) {
            printf(" %d", out[i][j]);
        }
        puts("");
    }
    return 0;
}


//============================================================================
// Name        : Discounts.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<stdio.h>
#include<utility>
#define min(x,y) ((x)<(y)?(x):(y))
using namespace std;
struct Node {
    int value;
    int id;
};
vector<int> out[1000];
vector<struct Node> ak, bk;
bool cmp(struct Node a, struct Node b) {
    return a.value > b.value;
}
int main() {
    //cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!
    int n, k;
    scanf(" %d %d", &n, &k);
    int i, j;
    double ans = 0;
    for (i = 0; i < n; i++) {
        int a, b;

        scanf(" %d %d", &a, &b);
        struct Node temp;
        temp.value = a;
        temp.id = i + 1;
        if (b & 1) {
            ak.push_back(temp);
        } else
            bk.push_back(temp);
        ans += a;
    }
    sort(ak.begin(), ak.end(), cmp);
    sort(bk.begin(), bk.end(), cmp);
    //printf("ans:%.3lf\n",ans);
    for (i = 0; i < k && i < ak.size(); i++) {
        out[i].push_back(ak[i].id);
        ans -= ak[i].value * .5;
    }

    //while(i<ak.size())
        //out[k-1].push_back(ak[i++].id);
    if (ak.size() >= k && bk.size()) {
        ans += ak[k - 1].value*.5;
        ans -= min(ak[ak.size() - 1].value * .5, bk[bk.size() - 1].value * .5);
        for (i = 0; i < bk.size(); i++) {
            out[k - 1].push_back(bk[i].id);
        }
    } else if (ak.size() < k) {
        for (j = 0; i < k&&j<bk.size(); i++, j++) {
            out[i].push_back(bk[j].id);
        }
        while (j < bk.size()) {
            out[k - 1].push_back(bk[j++].id);
        }
    }
    for(i=k;i<ak.size();i++)
        out[k-1].push_back(ak[i].id);
    printf("%.1lf\n", ans);
    for (i = 0; i < k; i++) {
        printf("%d", out[i].size());
        for (j = 0; j < out[i].size(); j++) {
            printf(" %d", out[i][j]);
        }
        puts("");
    }
    return 0;
}


//============================================================================
// Name        : Discounts.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<stdio.h>
#include<utility>
#define min(x,y) ((x)<(y)?(x):(y))
using namespace std;
struct Node {
    int value;
    int id;
};
vector<int> out[1000];
vector<struct Node> ak, bk;
bool cmp(struct Node a, struct Node b) {
    return a.value > b.value;
}
int main() {
    //cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!
    int n, k;
    scanf(" %d %d", &n, &k);
    int i, j;
    double ans = 0;
    for (i = 0; i < n; i++) {
        int a, b;

        scanf(" %d %d", &a, &b);
        struct Node temp;
        temp.value = a;
        temp.id = i + 1;
        if (b & 1) {
            ak.push_back(temp);
        } else
            bk.push_back(temp);
        ans += a;
    }
    sort(ak.begin(), ak.end(), cmp);
    sort(bk.begin(), bk.end(), cmp);
    //printf("ans:%.3lf\n",ans);
    for (i = 0; i < k && i < ak.size(); i++) {
        out[i].push_back(ak[i].id);
        ans -= ak[i].value * .5;
    }
    //while(i<ak.size())
        //out[k-1].push_back(ak[i++].id);
    if (ak.size() >= k && bk.size()) {
        ans += ak[k - 1].value*.5;

        ans -= min(ak[ak.size() - 1].value * .5, bk[bk.size() - 1].value * .5);
        for(i=k;i<ak.size();i++)
            out[k-1].push_back(ak[i].id);
        for (i = 0; i < bk.size(); i++) {
            out[k - 1].push_back(bk[i].id);
        }
    } else if (ak.size() < k) {
        for (j = 0; i < k&&j<bk.size(); i++, j++) {
            out[i].push_back(bk[j].id);
        }
        while (j < bk.size()) {
            out[k - 1].push_back(bk[j++].id);
        }
    }
    printf("%.1lf\n", ans);
    for (i = 0; i < k; i++) {
        printf("%d", out[i].size());
        for (j = 0; j < out[i].size(); j++) {
            printf(" %d", out[i][j]);
        }
        puts("");
    }
    return 0;
}


//============================================================================
// Name        : Discounts.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<stdio.h>
#include<utility>
#define min(x,y) ((x)<(y)?(x):(y))
using namespace std;
struct Node {
    int value;
    int id;
};
vector<int> out[1000];
vector<struct Node> ak, bk;
bool cmp(struct Node a, struct Node b) {
    return a.value > b.value;
}
int main() {
    //cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!
    int n, k;
    scanf(" %d %d", &n, &k);
    int i, j;
    double ans = 0;
    for (i = 0; i < n; i++) {
        int a, b;

        scanf(" %d %d", &a, &b);
        struct Node temp;
        temp.value = a;
        temp.id = i + 1;
        if (b & 1) {
            ak.push_back(temp);
        } else
            bk.push_back(temp);
        ans += a;
    }
    sort(ak.begin(), ak.end(), cmp);
    sort(bk.begin(), bk.end(), cmp);
    //printf("ans:%.3lf\n",ans);
    for (i = 0; i < k && i < ak.size(); i++) {
        out[i].push_back(ak[i].id);
        ans -= ak[i].value * .5;
    }
    for(i=k;i<ak.size();i++)
        out[k-1].push_back(ak[i].id);
    //while(i<ak.size())
        //out[k-1].push_back(ak[i++].id);
    if (ak.size() >= k && bk.size()) {
        ans += ak[k - 1].value*.5;

        ans -= min(ak[ak.size() - 1].value * .5, bk[bk.size() - 1].value * .5);

        for (i = 0; i < bk.size(); i++) {
            out[k - 1].push_back(bk[i].id);
        }
    } else if (ak.size() < k) {
        for (j = 0; i < k&&j<bk.size(); i++, j++) {
            out[i].push_back(bk[j].id);
        }
        while (j < bk.size()) {
            out[k - 1].push_back(bk[j++].id);
        }
    }
    printf("%.1lf\n", ans);
    for (i = 0; i < k; i++) {
        printf("%d", out[i].size());
        for (j = 0; j < out[i].size(); j++) {
            printf(" %d", out[i][j]);
        }
        puts("");
    }
    return 0;
}


//============================================================================
// Name        : Discounts.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<stdio.h>
#include<utility>
#define min(x,y) ((x)<(y)?(x):(y))
using namespace std;
struct Node {
    int value;
    int id;
};
vector<int> out[1000];
vector<struct Node> ak, bk;
bool cmp(struct Node a, struct Node b) {
    return a.value > b.value;
}
int main() {
    //cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!
    int n, k;
    scanf(" %d %d", &n, &k);
    int i, j;
    double ans = 0;
    for (i = 0; i < n; i++) {
        int a, b;

        scanf(" %d %d", &a, &b);
        struct Node temp;
        temp.value = a;
        temp.id = i + 1;
        if (b & 1) {
            ak.push_back(temp);
        } else
            bk.push_back(temp);
        ans += a;
    }
    sort(ak.begin(), ak.end(), cmp);
    sort(bk.begin(), bk.end(), cmp);
    //printf("ans:%.3lf\n",ans);
    for (i = 0; i < k && i < ak.size(); i++) {
        out[i].push_back(ak[i].id);
        ans -= ak[i].value * .5;
    }
    while(i<ak.size())
        out[i].push_back(ak[i++].id);
    if (ak.size() >= k && bk.size()) {
        ans += ak[k - 1].value*.5;

        ans -= min(ak[ak.size() - 1].value * .5, bk[bk.size() - 1].value * .5);
        for (i = 0; i < bk.size(); i++) {
            out[k - 1].push_back(bk[i].id);
        }
    } else if (ak.size() < k) {
        for (j = 0; i < k&&j<bk.size(); i++, j++) {
            out[i].push_back(bk[j].id);
        }
        while (j < bk.size()) {
            out[k - 1].push_back(bk[j++].id);
        }
    }
    printf("%.1lf\n", ans);
    for (i = 0; i < k; i++) {
        printf("%d", out[i].size());
        for (j = 0; j < out[i].size(); j++) {
            printf(" %d", out[i][j]);
        }
        puts("");
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define sc( x ) scanf( "%d" , &x )
#define REP( i , n ) for( int i = 0 ; i < n ; ++i )
#define clr( t , val ) memset( t , val , sizeof( t ) )

#define pb push_back
#define all( v ) v.begin() , v.end()
#define rall( v ) v.rbegin() , v.rend()
#define SZ( v ) ((int)(v).size())

#define mp make_pair
#define fi first
#define se second

#define N 1000

typedef pair< int , int > pii;
typedef vector< pii > vpii;
typedef vector< int > vi;
typedef vector< vi > vvi;

int n;
vector< pair< pii , int > > v;
vi tools;
double AC[ N + 5 ];
vvi vec;
int firstLess( vi v , int x ){
	vector< int > :: reverse_iterator it = lower_bound( rall( v ) , x , greater< int >() );
	if( it != v.rend() ) return *it;
	return -1;
}

double solve( int b , int k ){
    if( b < 0 ) return 0;
    int pos = firstLess( tools , b );
    if( k == 1 ) {
        vi temp;
        for( int i = b ; i >= 0 ; --i ) temp.pb( v[ i ].se );
        vec.pb( temp );
        if( pos != -1 ) return AC[ b + 1 ] - 0.5 * (double)v[ 0 ].fi.fi;
        return AC[ b + 1 ];
    }

    if( pos != -1 ){
        vi temp;
        for( int i = b ; i >= pos ; --i ) temp.pb( v[ i ].se );
        vec.pb( temp );
        if( pos != -1 ) return AC[ b + 1 ] - AC[ pos ] - 0.5 * (double)v[ pos ].fi.fi + solve( pos - 1 , k - 1 );
    }else{
        vi temp;
        for( int i = b ; i >= 0 ; --i ) temp.pb( v[ i ].se );
        vec.pb( temp );
		return AC[ b + 1 ];
    }
}
void impr(){
    REP( i , SZ( vec ) ){
        printf( "%d" , SZ( vec[ i ] ) );
        REP( j , SZ( vec[ i ] ) ) printf( " %d" , vec[ i ][ j ] + 1 );
        puts( "" );
    }
}
void fix( int k ){
    int i = 0;
    while( SZ( vec ) < k ){
        if( SZ( vec[ i ] ) == 1 ) {
            i ++;
            continue;
        }
        vi temp = vec[ i ];
        while( SZ( vec ) < k && SZ( temp ) > 1 ){
            int val = temp.back();
            vec.pb( vi( 1 , val ) );
            temp.pop_back();
        }
        vec[ i ] = temp;
        i ++;
    }
}
int main(){
    int k , cost , type ;
    while( sc( n ) == 1 ){
        sc( k );
        v.clear();
        vec.clear();
        REP( i , n ){
            sc( cost ) , sc( type );
            v.pb( mp( mp( cost , type ) , i ) );
        }
        sort( all( v ) );
        tools.clear();
        REP( i , n ) if( v[ i ].fi.se == 1 ) tools.pb( i );
        AC[ 0 ] = 0;
        for( int i = 1 ; i <= n ; ++ i ) AC[ i ] = AC[ i - 1 ] + (double) v[ i - 1 ].fi.fi;
        printf( "%.1f\n" , (double)solve( n - 1 , k ) );
        //fix( k );
        impr();
    }
}


#include <bits/stdc++.h>

#define ll long long
#define ull unsigned long long
#define all(v)  v.begin() , v.end()
#define rall(v)  v.rbegin() , v.rend()
#define FOR(it,A) for(typeof A.begin() it = A.begin(); it!=A.end(); it++)
#define REP(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define vi vector<int>
#define vll vector<ll>
#define vull vector<ull>
#define vvi vector< vector<int> >
#define pii pair< int , int >
#define pll pair< ll , ll >
#define mp make_pair
#define fi first
#define se second
#define sc(x) scanf("%d",&x)
#define me(t,val) memset( t , val , sizeof(t) )
#define ones(x) __builtin_popcount(x)
#define test puts("test");
#define sync ios_base::sync_with_stdio(false);

#define N 100005
#define MOD 1000000007
#define INF (1<<30)
#define EPS (1e-5)

using namespace std;

int main()
{
	int n , k;
	while( cin >> n >> k )
	{
		vector< pii > v, w;
		int cost , t;
		REP( i , n )
		{
			cin >> cost >> t;
			if( t == 1 )
				v.pb( mp( cost , i ) );
			else w.pb( mp( cost , i ) );
		}
		sort( rall( v ) );
		sort( rall( w ) );
		int nv = v.size() , nw = w.size();
		double ans = 0;
		vector< vector< pair< pii , int > > > V( k );
		REP( i , nv )
			V[ min( i , k - 1 ) ].pb( mp( mp( v[i].fi , 1 ) ,v[i].se ) );
		if( nv >= k - 1 )
		{
			REP( i , nw )
				V.back().pb( mp( mp( w[i].fi , 2 ) ,w[i].se ) );
		}
		else
		{
			REP( i , nw )
				V[ min( nv + i , k - 1 ) ].pb( mp( mp( w[i].fi , 2 ) ,w[i].se ) );
		}
		REP( i , k ) sort( all(V[i] ) );
		REP( i , min( nv , k ) )
			ans -= 0.5*V[i][0].fi.fi;
		REP( i , k )
			REP( j , V[i].size() )
				ans += V[i][j].fi.fi;
		printf( "%.1lf\n" , ans );
		REP( i , k )
		{
			printf( "%d" , V[i].size() );
			REP( j , V[i].size() )
				printf( " %d" , V[i][j].se + 1 );
			puts("");
		}
	}
}


#include<bits/stdc++.h>
using namespace std;

#define sc( x ) scanf( "%d" , &x )
#define REP( i , n ) for( int i = 0 ; i < n ; ++i )
#define clr( t , val ) memset( t , val , sizeof( t ) )

#define pb push_back
#define all( v ) v.begin() , v.end()
#define SZ( v ) ((int)(v).size())

#define mp make_pair
#define fi first
#define se second

#define N 1000

typedef pair< int , int > pii;
typedef vector< pii > vpii;
typedef vector< int > vi;
typedef vector< vi > vvi;

int n;
vector< pair< pii , int > > v;
vi tools;
double AC[ N + 5 ];
vvi vec;
double solve( int a , int k ){
    if( a >= n ) return 0;
    int ind = lower_bound( all( tools ) , a ) - tools.begin();
    int pos = ind < SZ( tools) ? tools[ ind ] : -1;
    if( k == 1 ) {
        vi temp;
        for( int i = a ; i < n ; ++i ) temp.pb( v[ i ].se );
        vec.pb( temp );
        if( ind != SZ( tools ) ) return AC[ n ] - AC[ a ] - 0.5 * (double)v[ pos ].fi.fi;
        return AC[ n ] - AC[ a ];
    }

    if( a <= pos && ind != SZ( tools ) ){
        vi temp;
        for( int i = a ; i <= pos  ; ++i ) temp.pb( v[ i ].se );
        vec.pb( temp );
        return AC[ pos + 1 ] - AC[ a ] - 0.5 * (double)v[ pos ].fi.fi + solve( pos + 1 , k - 1 );
    }else{
        vi temp;
        for( int i = a ; i < n ; ++i ) temp.pb( v[ i ].se );
        vec.pb( temp );
        return AC[ n ] - AC[ a ];
    }
}
void impr(){
    REP( i , SZ( vec ) ){
        printf( "%d" , SZ( vec[ i ] ) );
        REP( j , SZ( vec[ i ] ) ) printf( " %d" , vec[ i ][ j ] + 1 );
        puts( "" );
    }
}
void fix( int k ){
    int i = 0;
    while( SZ( vec ) < k ){
        if( SZ( vec[ i ] ) == 1 ) {
            i ++;
            continue;
        }
        vi temp = vec[ i ];
        while( SZ( vec ) < k && SZ( temp ) > 1 ){
            int val = temp.back();
            vec.pb( vi( 1 , val ) );
            temp.pop_back();
        }
        vec[ i ] = temp;
        i ++;
    }
}
int main(){
    int k , cost , type ;
    while( sc( n ) == 1 ){
        sc( k );
        v.clear();
        vec.clear();
        REP( i , n ){
            sc( cost ) , sc( type );
            v.pb( mp( mp( cost , type ) , i ) );
        }
        sort( all( v ) );
        reverse( all( v ) );
        tools.clear();
        REP( i , n ) if( v[ i ].fi.se == 1 ) tools.pb( i );
        AC[ 0 ] = 0;
        for( int i = 1 ; i <= n ; ++ i ) AC[ i ] = AC[ i - 1 ] + (double) v[ i - 1 ].fi.fi;
        printf( "%.1f\n" , (double)solve( 0 , k ) );
        fix( k );
        impr();
    }
}


#include <bits/stdc++.h>

#define ll long long
#define ull unsigned long long
#define all(v)  v.begin() , v.end()
#define rall(v)  v.rbegin() , v.rend()
#define FOR(it,A) for(typeof A.begin() it = A.begin(); it!=A.end(); it++)
#define REP(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define vi vector<int>
#define vll vector<ll>
#define vull vector<ull>
#define vvi vector< vector<int> >
#define pii pair< int , int >
#define pll pair< ll , ll >
#define mp make_pair
#define fi first
#define se second
#define sc(x) scanf("%d",&x)
#define me(t,val) memset( t , val , sizeof(t) )
#define ones(x) __builtin_popcount(x)
#define test puts("test");
#define sync ios_base::sync_with_stdio(false);

#define N 100005
#define MOD 1000000007
#define INF (1<<30)
#define EPS (1e-5)

using namespace std;

int main()
{
	int n , k;
	while( cin >> n >> k )
	{
		vector< pii > v, w;
		int cost , t;
		REP( i , n )
		{
			cin >> cost >> t;
			if( t == 1 )
				v.pb( mp( cost , i ) );
			else w.pb( mp( cost , i ) );
		}
		sort( rall( v ) );
		sort( rall( w ) );
		int nv = v.size() , nw = w.size();
		double ans = 0;
		vector< vector< pair< pii , int > > > V( k );
		REP( i , nv )
			V[ min( i , k - 1 ) ].pb( mp( mp( v[i].fi , 1 ) ,v[i].se ) );
		if( nv >= k - 1 )
		{
			REP( i , nw )
				V.back().pb( mp( mp( w[i].fi , 2 ) ,w[i].se ) );
		}
		else
		{
			REP( i , nw )
				V[ min( nv + i , k - 1 ) ].pb( mp( mp( w[i].fi , 2 ) ,w[i].se ) );
		}
		REP( i , k ) sort( all(V[i] ) );
		REP( i , k )
			if( V[i][0].fi.se == 1 )ans -= 0.5*V[i][0].fi.fi;
		REP( i , k )
			REP( j , V[i].size() )
				ans += V[i][j].fi.fi;
		printf( "%.1lf\n" , ans );

	}
}


#include <bits/stdc++.h>

#define ll long long
#define ull unsigned long long
#define all(v)  v.begin() , v.end()
#define rall(v)  v.rbegin() , v.rend()
#define FOR(it,A) for(typeof A.begin() it = A.begin(); it!=A.end(); it++)
#define REP(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define vi vector<int>
#define vll vector<ll>
#define vull vector<ull>
#define vvi vector< vector<int> >
#define pii pair< int , int >
#define pll pair< ll , ll >
#define mp make_pair
#define fi first
#define se second
#define sc(x) scanf("%d",&x)
#define me(t,val) memset( t , val , sizeof(t) )
#define ones(x) __builtin_popcount(x)
#define test puts("test");
#define sync ios_base::sync_with_stdio(false);

#define N 100005
#define MOD 1000000007
#define INF (1<<30)
#define EPS (1e-5)

using namespace std;

int main()
{
	int n , k;
	while( cin >> n >> k )
	{
		vector< pii > v, w;
		int cost , t;
		REP( i , n )
		{
			cin >> cost >> t;
			if( t == 1 )
				v.pb( mp( cost , i ) );
			else w.pb( mp( cost , i ) );
		}
		sort( rall( v ) );
		sort( rall( w ) );
		int nv = v.size() , nw = w.size();
		double ans = 0;
		vector< vector< pair< pii , int > > > V( k );
		REP( i , nv )
			V[ min( i , k - 1 ) ].pb( mp( mp( v[i].fi , 1 ) ,v[i].se ) );
		if( nv >= k - 1 )
		{
			REP( i , nw )
				V.back().pb( mp( mp( w[i].fi , 2 ) ,w[i].se ) );
		}
		else
		{
			REP( i , nw )
				V[ min( nv + i , k - 1 ) ].pb( mp( mp( w[i].fi , 2 ) ,w[i].se ) );
		}
		REP( i , k ) sort( all(V[i] ) );
		REP( i , k )
			if( V[i][0].fi.se == 1 )ans -= 0.5*V[i][0].fi.fi;
		REP( i , k )
			REP( j , V[i].size() )
				ans += V[i][j].fi.fi;
		printf( "%.1lf\n" , ans );
		REP( i , k )
		{
			printf( "%d" , V[i].size() );
			REP( j , V[i].size() )
				printf( " %d" , V[i][j].se + 1 );
			puts("");
		}
	}
}


#include<bits/stdc++.h>
using namespace std;

#define sc( x ) scanf( "%d" , &x )
#define REP( i , n ) for( int i = 0 ; i < n ; ++i )
#define clr( t , val ) memset( t , val , sizeof( t ) )

#define pb push_back
#define all( v ) v.begin() , v.end()
#define SZ( v ) ((int)(v).size())

#define mp make_pair
#define fi first
#define se second

#define N 1000

typedef pair< int , int > pii;
typedef vector< pii > vpii;
typedef vector< int > vi;
typedef vector< vi > vvi;

int n;
vector< pair< pii , int > > v;
vi tools;
double AC[ N + 5 ];
vvi vec;
double solve( int a , int k ){
    if( a >= n ) return 0;
    int ind = lower_bound( all( tools ) , a ) - tools.begin();
    int pos = ind < SZ( tools) ? tools[ ind ] : -1;
    if( k == 1 ) {
        vi temp;
        for( int i = a ; i < n ; ++i ) temp.pb( v[ i ].se );
        vec.pb( temp );
        if( ind != SZ( tools ) ) return AC[ n ] - AC[ a ] - 0.5 * (double)v[ pos ].fi.fi;
        return AC[ n ] - AC[ a ];
    }

    if( a <= pos && ind != SZ( tools ) ){
        vi temp;
        for( int i = a ; i <= pos  ; ++i ) temp.pb( v[ i ].se );
        vec.pb( temp );
        return AC[ pos + 1 ] - AC[ a ] - 0.5 * (double)v[ pos ].fi.fi + solve( pos + 1 , k - 1 );
    }else{
        vi temp;
        for( int i = a ; i < n ; ++i ) temp.pb( v[ i ].se );
        vec.pb( temp );
        return AC[ n ] - AC[ a ];
    }
}
void impr(){
    REP( i , SZ( vec ) ){
        printf( "%d" , SZ( vec[ i ] ) );
        REP( j , SZ( vec[ i ] ) ) printf( " %d" , vec[ i ][ j ] + 1 );
        puts( "" );
    }
}
void fix( int k ){
    int i = 0;
    while( SZ( vec ) < k ){
        if( SZ( vec[ i ] ) == 1 ) {
            i ++;
            continue;
        }
        vi temp = vec[ i ];
        while( SZ( vec ) < k && SZ( temp ) > 1 ){
            int val = temp.back();
            vec.pb( vi( 1 , val ) );
            temp.pop_back();
        }
        vec[ i ] = temp;
        i ++;
    }
}
int main(){
    int k , cost , type ;
    while( sc( n ) == 1 ){
        sc( k );
        v.clear();
        vec.clear();
        REP( i , n ){
            sc( cost ) , sc( type );
            v.pb( mp( mp( cost , type == 2 ? 1 : 2 ) , i ) );
        }
        sort( all( v ) );
        reverse( all( v ) );
        tools.clear();
        REP( i , n ) if( v[ i ].fi.se == 2 ) tools.pb( i );
        AC[ 0 ] = 0;
        for( int i = 1 ; i <= n ; ++ i ) AC[ i ] = AC[ i - 1 ] + (double) v[ i - 1 ].fi.fi;
        printf( "%.1f\n" , (double)solve( 0 , k ) );
        fix( k );
        impr();
    }
}


#include<bits/stdc++.h>
using namespace std;

#define sc( x ) scanf( "%d" , &x )
#define REP( i , n ) for( int i = 0 ; i < n ; ++i )
#define clr( t , val ) memset( t , val , sizeof( t ) )

#define pb push_back
#define all( v ) v.begin() , v.end()
#define rall( v ) v.rbegin() , v.rend()
#define SZ( v ) ((int)(v).size())

#define mp make_pair
#define fi first
#define se second

#define N 1000

typedef pair< int , int > pii;
typedef vector< pii > vpii;
typedef vector< int > vi;
typedef vector< vi > vvi;

int n;
vector< pair< pii , int > > v;
vi tools;
double AC[ N + 5 ];
vvi vec;
int firstLess( vi v , int x ){
	vector< int > :: reverse_iterator it = lower_bound( rall( v ) , x , greater< int >() );
	if( it != v.rend() ) return *it;
	return -1;
}

double solve( int b , int k ){
    if( b < 0 ) return 0;
    int pos = firstLess( tools , b );
    if( k == 1 ) {
        vi temp;
        for( int i = b ; i >= 0 ; --i ) temp.pb( v[ i ].se );
        vec.pb( temp );
        if( pos != -1 ) return AC[ b + 1 ] - 0.5 * (double)v[ 0 ].fi.fi;
        return AC[ b + 1 ];
    }

    if( pos != -1 ){
        vi temp;
        for( int i = b ; i >= pos ; --i ) temp.pb( v[ i ].se );
        vec.pb( temp );
        if( pos != -1 ) return AC[ b + 1 ] - AC[ pos ] - 0.5 * (double)v[ pos ].fi.fi + solve( pos - 1 , k - 1 );
    }else{
        vi temp;
        for( int i = b ; i >= 0 ; --i ) temp.pb( v[ i ].se );
        vec.pb( temp );
		return AC[ b + 1 ];
    }
}
void impr(){
    REP( i , SZ( vec ) ){
        printf( "%d" , SZ( vec[ i ] ) );
        REP( j , SZ( vec[ i ] ) ) printf( " %d" , vec[ i ][ j ] + 1 );
        puts( "" );
    }
}
void fix( int k ){
    int i = 0;
    while( SZ( vec ) < k ){
        if( SZ( vec[ i ] ) == 1 ) {
            i ++;
            continue;
        }
        vi temp = vec[ i ];
        while( SZ( vec ) < k && SZ( temp ) > 1 ){
            int val = temp.back();
            vec.pb( vi( 1 , val ) );
            temp.pop_back();
        }
        vec[ i ] = temp;
        i ++;
    }
}
int main(){
    int k , cost , type ;
    while( sc( n ) == 1 ){
        sc( k );
        v.clear();
        vec.clear();
        REP( i , n ){
            sc( cost ) , sc( type );
            v.pb( mp( mp( cost , type ) , i ) );
        }
        sort( all( v ) );
        tools.clear();
        REP( i , n ) if( v[ i ].fi.se == 1 ) tools.pb( i );
        AC[ 0 ] = 0;
        for( int i = 1 ; i <= n ; ++ i ) AC[ i ] = AC[ i - 1 ] + (double) v[ i - 1 ].fi.fi;
        printf( "%.1f\n" , (double)solve( n - 1 , k ) );
        fix( k );
        impr();
    }
}


#include<cstdio>
#include<algorithm>
#include<iostream>
#include<vector>
using namespace std;
#define MAXN 1010

class item
{
    public:
        int n;
        int p;
        item(int n,int p):n(n),p(p){}
};
vector<item> st,p;
int N,K;

bool cmp(const item a,const item b)
{
    return a.p>b.p;
}
int main()
{
    cin>>N>>K;
    double ans=0;
    for(int i=1;i<=N;i++)
    {
        int a,b;
        scanf("%d%d",&a,&b);
        item tmp(i,a);
        if(b==1) st.push_back(tmp);
        else p.push_back(tmp);
        ans+=a;
    }
    sort(st.begin(),st.end(),cmp);
    sort(p.begin(),p.end(),cmp);

    for(int i=0;i<min(K,(int)st.size())-1;i++) ans-=1.0*st[i].p/2;
    ans-=1.0*st[st.size()-1].p/2;
    if(K<=st.size() and p[p.size()-1].p<st[K-1].p)
        ans+=(1.0*p[p.size()-1].p-st[K-1].p)/2;
    printf("%.1lf\n",ans);
    if(K<=st.size())
    {
        for(int i=0;i+1<st.size()and i<K-1;i++) cout<<1<<" "<<st[i].n<<endl;
        cout<<p.size()+st.size()-K+1;
        for(int i=K-1;i<st.size();i++) cout<<" "<<st[i].n;
        for(int i=0;i<p.size();i++) cout<<" "<<p[i].n;
        cout<<endl;
    }
    else
    {
        for(int i=0;i<st.size();i++) cout<<1<<" "<<st[i].n<<endl;
        for(int i=0;i+st.size()<K-1;i++) cout<<1<<" "<<p[i].n<<endl;
        cout<<st.size()+p.size()-K+1;
        for(int i=K-1-st.size();i<p.size();i++) cout<<" "<<p[i].n;
        cout<<endl;
    }
    return 0;
}


#include<cstdio>
#include<algorithm>
#include<iostream>
#include<vector>
using namespace std;
#define MAXN 1010

class item
{
    public:
        int n;
        int p;
        item(int n,int p):n(n),p(p){}
};
vector<item> st,p;
int N,K;

bool cmp(const item a,const item b)
{
    return a.p>b.p;
}
int main()
{
    cin>>N>>K;
    double ans=0;
    for(int i=1;i<=N;i++)
    {
        int a,b;
        scanf("%d%d",&a,&b);
        item tmp(i,a);
        if(b==1) st.push_back(tmp);
        else p.push_back(tmp);
        ans+=a;
    }
    sort(st.begin(),st.end(),cmp);
    sort(p.begin(),p.end(),cmp);

    for(int i=0;i<min(K,(int)st.size());i++) ans-=1.0*st[i].p/2;
    if(K<st.size() and p[p.size()-1].p<st[K-1].p)
        ans+=1.0*(p[p.size()-1].p-st[K-1].p)/2;
    printf("%.1lf\n",ans);
    for(int i=0;i<min(K,(int)st.size())-1;i++)
        cout<<1<<" "<<st[i].n<<endl;
    if(K<=st.size())
    {
        cout<<p.size()+st.size()-K+1<<" ";
        for(int i=K-1;i<st.size();i++) cout<<st[i].n<<" ";
        for(int i=0;i<p.size()-1;i++) cout<<p[i].n<<" ";
        cout<<p[p.size()-1].n<<endl;
    }
    else
    {
        for(int i=0;i+st.size()<K-1;i++) cout<<1<<" "<<p[i].n<<endl;
        cout<<st.size()+p.size()-K+1<<" ";
        for(int i=K-1-st.size();i<p.size()-1;i++) cout<<p[i].n<<" ";
        cout<<p[p.size()-1].n<<endl;
    }
    return 0;
}


#include<cstdio>
#include<algorithm>
#include<iostream>
#include<vector>
using namespace std;
#define MAXN 1010

class item
{
    public:
        int n;
        int p;
        item(int n,int p):n(n),p(p){}
};
vector<item> st,p;
int N,K;

bool cmp(const item a,const item b)
{
    return a.p>b.p;
}
int main()
{
    cin>>N>>K;
    double ans=0;
    for(int i=1;i<=N;i++)
    {
        int a,b;
        scanf("%d%d",&a,&b);
        item tmp(i,a);
        if(b==1) st.push_back(tmp);
        else p.push_back(tmp);
        ans+=a;
    }
    sort(st.begin(),st.end(),cmp);
    sort(p.begin(),p.end(),cmp);

    for(int i=0;i<min(K,(int)st.size());i++) ans-=1.0*st[i].p/2;
    if(K<st.size() and p[p.size()-1].p<st[K-1].p)
        ans+=1.0*(p[p.size()-1].p-st[K-1].p)/2;
    printf("%.1lf\n",ans);
    if(K<=st.size())
    {
        for(int i=0;i+1<st.size();i++) cout<<1<<" "<<st[i].n<<endl;
        cout<<p.size()+st.size()-K+1;
        for(int i=K-1;i<st.size();i++) cout<<" "<<st[i].n;
        for(int i=0;i<p.size();i++) cout<<" "<<p[i].n;
        cout<<endl;
    }
    else
    {
        for(int i=0;i<st.size();i++) cout<<1<<" "<<st[i].n<<endl;
        for(int i=0;i+st.size()<K-1;i++) cout<<1<<" "<<p[i].n<<endl;
        cout<<st.size()+p.size()-K+1;
        for(int i=K-1-st.size();i<p.size();i++) cout<<" "<<p[i].n;
        cout<<endl;
    }
    return 0;
}


#include<cstdio>
#include<algorithm>
#include<iostream>
#include<vector>
using namespace std;
#define MAXN 1010

class item
{
    public:
        int n;
        int p;
        item(int n,int p):n(n),p(p){}
};
vector<item> st,p;
int N,K;

bool cmp(const item a,const item b)
{
    return a.p>b.p;
}
int main()
{
    cin>>N>>K;
    double ans=0;
    for(int i=1;i<=N;i++)
    {
        int a,b;
        scanf("%d%d",&a,&b);
        item tmp(i,a);
        if(b==1) st.push_back(tmp);
        else p.push_back(tmp);
        ans+=a;
    }
    sort(st.begin(),st.end(),cmp);
    sort(p.begin(),p.end(),cmp);

    for(int i=0;i<min(K,(int)st.size())-1;i++) ans-=1.0*st[i].p/2;
    if(st.size()) ans-=1.0*st[st.size()-1].p/2;
    if(p.size() and K<=st.size() and p[p.size()-1].p<st[K-1].p)
        ans+=(1.0*p[p.size()-1].p-st[K-1].p)/2;
    printf("%.1lf\n",ans);
    if(K<=st.size())
    {
        for(int i=0;i+1<st.size()and i<K-1;i++) cout<<1<<" "<<st[i].n<<endl;
        cout<<p.size()+st.size()-K+1;
        for(int i=K-1;i<st.size();i++) cout<<" "<<st[i].n;
        for(int i=0;i<p.size();i++) cout<<" "<<p[i].n;
        cout<<endl;
    }
    else
    {
        for(int i=0;i<st.size();i++) cout<<1<<" "<<st[i].n<<endl;
        for(int i=0;i+st.size()<K-1;i++) cout<<1<<" "<<p[i].n<<endl;
        cout<<st.size()+p.size()-K+1;
        for(int i=K-1-st.size();i<p.size();i++) cout<<" "<<p[i].n;
        cout<<endl;
    }
    return 0;
}


#include<cstdio>
#include<algorithm>
#include<iostream>
#include<vector>
using namespace std;
#define MAXN 1010

class item
{
    public:
        int n;
        int p;
        item(int n,int p):n(n),p(p){}
};
vector<item> st,p;
int N,K;

bool cmp(const item a,const item b)
{
    return a.p>b.p;
}
int main()
{
    cin>>N>>K;
    double ans=0;
    for(int i=1;i<=N;i++)
    {
        int a,b;
        scanf("%d%d",&a,&b);
        item tmp(i,a);
        if(b==1) st.push_back(tmp);
        else p.push_back(tmp);
        ans+=a;
    }
    sort(st.begin(),st.end(),cmp);
    sort(p.begin(),p.end(),cmp);

    for(int i=0;i<min(K,(int)st.size())-1;i++) ans-=1.0*st[i].p/2;
    if(st.size()) ans-=1.0*st[st.size()-1].p/2;
    if(K<=st.size() and p[p.size()-1].p<st[K-1].p)
        ans+=(1.0*p[p.size()-1].p-st[K-1].p)/2;
    printf("%.1lf\n",ans);
    if(K<=st.size())
    {
        for(int i=0;i+1<st.size()and i<K-1;i++) cout<<1<<" "<<st[i].n<<endl;
        cout<<p.size()+st.size()-K+1;
        for(int i=K-1;i<st.size();i++) cout<<" "<<st[i].n;
        for(int i=0;i<p.size();i++) cout<<" "<<p[i].n;
        cout<<endl;
    }
    else
    {
        for(int i=0;i<st.size();i++) cout<<1<<" "<<st[i].n<<endl;
        for(int i=0;i+st.size()<K-1;i++) cout<<1<<" "<<p[i].n<<endl;
        cout<<st.size()+p.size()-K+1;
        for(int i=K-1-st.size();i<p.size();i++) cout<<" "<<p[i].n;
        cout<<endl;
    }
    return 0;
}


#include<cstdio>
#include<algorithm>
#include<iostream>
#include<vector>
using namespace std;
#define MAXN 1010

class item
{
    public:
        int n;
        int p;
        item(int n,int p):n(n),p(p){}
};
vector<item> st,p;
int N,K;

bool cmp(const item a,const item b)
{
    return a.p>b.p;
}
int main()
{
    cin>>N>>K;
    double ans=0;
    for(int i=1;i<=N;i++)
    {
        int a,b;
        scanf("%d%d",&a,&b);
        item tmp(i,a);
        if(b==1) st.push_back(tmp);
        else p.push_back(tmp);
        ans+=a;
    }
    sort(st.begin(),st.end(),cmp);
    sort(p.begin(),p.end(),cmp);

    for(int i=0;i<min(K,(int)st.size())-1;i++) ans-=1.0*st[i].p/2;
    if(st.size()) ans-=1.0*st[st.size()-1].p/2;
    if(st.size()and p.size() and K<=st.size() and p[p.size()-1].p<st[st.size()-1].p)
        ans-=(1.0*p[p.size()-1].p-st[st.size()-1].p)/2;
    printf("%.1lf\n",ans);
    if(K<=st.size())
    {
        for(int i=0;i+1<st.size()and i<K-1;i++) cout<<1<<" "<<st[i].n<<endl;
        cout<<p.size()+st.size()-K+1;
        for(int i=K-1;i<st.size();i++) cout<<" "<<st[i].n;
        for(int i=0;i<p.size();i++) cout<<" "<<p[i].n;
        cout<<endl;
    }
    else
    {
        for(int i=0;i<st.size();i++) cout<<1<<" "<<st[i].n<<endl;
        for(int i=0;i+st.size()<K-1;i++) cout<<1<<" "<<p[i].n<<endl;
        cout<<st.size()+p.size()-K+1;
        for(int i=K-1-st.size();i<p.size();i++) cout<<" "<<p[i].n;
        cout<<endl;
    }
    return 0;
}


#include<cstdio>
#include<algorithm>
#include<iostream>
#include<vector>
using namespace std;
#define MAXN 1010

class item
{
    public:
        int n;
        int p;
        item(int n,int p):n(n),p(p){}
};
vector<item> st,p;
int N,K;

bool cmp(const item a,const item b)
{
    return a.p>b.p;
}
int main()
{
    cin>>N>>K;
    double ans=0;
    for(int i=1;i<=N;i++)
    {
        int a,b;
        scanf("%d%d",&a,&b);
        item tmp(i,a);
        if(b==1) st.push_back(tmp);
        else p.push_back(tmp);
        ans+=a;
    }
    sort(st.begin(),st.end(),cmp);
    sort(p.begin(),p.end(),cmp);

    for(int i=0;i<min(K,(int)st.size());i++) ans-=1.0*st[i].p/2;
    if(K<st.size() and p[p.size()-1].p<st[K-1].p)
        ans+=1.0*(p[p.size()-1].p-st[K-1].p)/2;
    printf("%.1lf\n",ans);
    for(int i=0;i<min(K,(int)st.size())-1;i++)
        cout<<1<<" "<<st[i].n<<endl;
    if(K<=st.size())
    {
        cout<<p.size()+st.size()-K+1<<" ";
        for(int i=K-1;i<st.size();i++) cout<<st[i].n<<" ";
        for(int i=0;i<p.size()-1;i++) cout<<p[i].n<<" ";
        cout<<p[p.size()-1].n<<endl;
    }
    else
    {
        cout<<1<<" "<<st[st.size()-1].n<<endl;
        for(int i=0;i+st.size()<K-1;i++) cout<<1<<" "<<p[i].n<<endl;
        cout<<st.size()+p.size()-K+1<<" ";
        for(int i=K-1-st.size();i<p.size()-1;i++) cout<<p[i].n<<" ";
        cout<<p[p.size()-1].n<<endl;
    }
    return 0;
}


#include<cstdio>
#include<algorithm>
#include<iostream>
#include<vector>
using namespace std;
#define MAXN 1010

class item
{
    public:
        int n;
        int p;
        item(int n,int p):n(n),p(p){}
};
vector<item> st,p;
int N,K;

bool cmp(const item a,const item b)
{
    return a.p>b.p;
}
int main()
{
    cin>>N>>K;
    double ans=0;
    for(int i=1;i<=N;i++)
    {
        int a,b;
        scanf("%d%d",&a,&b);
        item tmp(i,a);
        if(b==1) st.push_back(tmp);
        else p.push_back(tmp);
        ans+=a;
    }
    sort(st.begin(),st.end(),cmp);
    sort(p.begin(),p.end(),cmp);

    for(int i=0;i<min(K,(int)st.size());i++) ans-=1.0*st[i].p/2;
    if(K<st.size() and p[p.size()-1].p<st[K-1].p)
        ans+=1.0*(p[p.size()-1].p-st[K-1].p)/2;
    printf("%.1lf\n",ans);
    for(int i=0;i<min(K,(int)st.size())-1;i++)
        cout<<1<<" "<<st[i].n<<endl;
    if(K<=st.size())
    {
        cout<<p.size()+st.size()-K+1;
        for(int i=K-1;i<st.size();i++) cout<<" "<<st[i].n;
        for(int i=0;i<p.size();i++) cout<<" "<<p[i].n;
        cout<<endl;
    }
    else
    {
        cout<<1<<" "<<st[st.size()-1].n<<endl;
        for(int i=0;i+st.size()<K-1;i++) cout<<1<<" "<<p[i].n<<endl;
        cout<<st.size()+p.size()-K+1;
        for(int i=K-1-st.size();i<p.size();i++) cout<<" "<<p[i].n;
        cout<<endl;
    }
    return 0;
}


#include<cstdio>
#include<algorithm>
#include<iostream>
#include<vector>
using namespace std;
#define MAXN 1010

class item
{
    public:
        int n;
        int p;
        item(int n,int p):n(n),p(p){}
};
vector<item> st,p;
int N,K;

bool cmp(const item a,const item b)
{
    return a.p>b.p;
}
int main()
{
    cin>>N>>K;
    double ans=0;
    for(int i=1;i<=N;i++)
    {
        int a,b;
        scanf("%d%d",&a,&b);
        item tmp(i,a);
        if(b==1) st.push_back(tmp);
        else p.push_back(tmp);
        ans+=a;
    }
    sort(st.begin(),st.end(),cmp);
    sort(p.begin(),p.end(),cmp);

    for(int i=0;i<min(K,(int)st.size());i++) ans-=1.0*st[i].p/2;
    if(K<st.size() and p[p.size()-1].p<st[K-1].p)
        ans+=1.0*(p[p.size()-1].p-st[K-1].p)/2;
    printf("%.1lf\n",ans);
    if(K<=st.size())
    {
        for(int i=0;i+1<st.size()and i<K-1;i++) cout<<1<<" "<<st[i].n<<endl;
        cout<<p.size()+st.size()-K+1;
        for(int i=K-1;i<st.size();i++) cout<<" "<<st[i].n;
        for(int i=0;i<p.size();i++) cout<<" "<<p[i].n;
        cout<<endl;
    }
    else
    {
        for(int i=0;i<st.size();i++) cout<<1<<" "<<st[i].n<<endl;
        for(int i=0;i+st.size()<K-1;i++) cout<<1<<" "<<p[i].n<<endl;
        cout<<st.size()+p.size()-K+1;
        for(int i=K-1-st.size();i<p.size();i++) cout<<" "<<p[i].n;
        cout<<endl;
    }
    return 0;
}


#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#define mp make_pair
#define pb push_back
#define MAXN 0X800
#define MAX 0XFFFFFFF
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;

const int dx[] = {0,1,0,-1};
const int dy[] = {1,0,-1,0};

struct Node
{
	int n,v;
	bool operator < (const Node& a) const
	{
		return v<a.v;
	}
};

LL sum;
double ans;
int l,m,v,t,n,k;
Node a[MAXN], b[MAXN];

int main()
{
	scanf("%d%d",&n,&k);
	l = m = sum = 0;
	for (int i=0; i<n; ++i)
	{
		scanf("%d%d",&v,&t);
		sum += v;
		if (t==1)
		{
			a[m].v = v;
			a[m++].n = i+1;
		}
		else
		{
			b[l].v = v;
			b[l++].n = i+1;
		}
	}
	sort(a,a+m);
	sort(b,b+l);
	ans = 0;
	if (m>=k)
	{
		for (int i=1; i<k; ++i)	ans += a[m-k+i].v/2.0;
		if (l>0)	ans += min(b[0].v,a[0].v)/2.0;
		else	ans += a[0].v/2.0;
		ans = sum-ans;
		printf("%.1f\n",ans);
		printf("%d",n-(k-1));
		for (int i=0; i<l; ++i)
			printf(" %d",b[i].n);
		for (int i=0; i<=m-k; ++i)
			printf(" %d",a[i].n);
		printf("\n");
		for (int i=1; i<k; ++i)
			printf("1 %d\n",a[m-k+i].n);
	}
	else
	{
		for (int i=0; i<m; ++i)	ans += a[i].v/2.0;
		ans = sum-ans;
		printf("%.1f\n",ans);
		for (int i=0; i<m; ++i)
			printf("1 %d\n",a[i].n);
		for (int i=m; i<k-1; ++i)
			printf("1 %d\n",b[i-m].n);
		printf("%d",n-k+1);
		for (int i=k-m-1; i<l; ++i)
			printf(" %d",b[i].n);
		printf("\n");
	}

	return 0;
}


#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#define mp make_pair
#define pb push_back
#define MAXN 0X800
#define MAX 0XFFFFFFF
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;

const int dx[] = {0,1,0,-1};
const int dy[] = {1,0,-1,0};

struct Node
{
	int n,v;
	bool operator < (const Node& a) const
	{
		return v<a.v;
	}
};

double ans;
int l,m,v,t,n,k,sum;
Node a[MAXN], b[MAXN];

int main()
{
	scanf("%d%d",&n,&k);
	l = m = sum = 0;
	for (int i=0; i<n; ++i)
	{
		scanf("%d%d",&v,&t);
		sum += v;
		if (t==1)
		{
			a[m].v = v;
			a[m++].n = i+1;
		}
		else
		{
			b[l].v = v;
			b[l++].n = i+1;
		}
	}
	sort(a,a+m);
	sort(b,b+l);
	ans = 0;
	if (m>=k)
	{
		for (int i=1; i<k; ++i)	ans += a[m-k+i].v/2.0;
		ans += min(b[0].v,a[0].v)/2.0;
		ans = sum-ans;
		printf("%.1f\n",ans);
		printf("%d",n-(k-1));
		for (int i=0; i<l; ++i)
			printf(" %d",b[i].n);
		for (int i=0; i<=m-k; ++i)
			printf(" %d",a[i].n);
		printf("\n");
		for (int i=1; i<k; ++i)
			printf("1 %d\n",a[m-k+i].n);
	}
	else
	{
		for (int i=0; i<m; ++i)	ans += a[i].v/2.0;
		ans = sum-ans;
		printf("%.1f\n",ans);
		for (int i=0; i<m; ++i)
			printf("1 %d\n",a[i].n);
		for (int i=m; i<k-1; ++i)
			printf("1 %d\n",b[i-m].n);
		printf("%d",n-k+1);
		for (int i=k-m-1; i<l; ++i)
			printf(" %d",b[i].n);
		printf("\n");
	}

	return 0;
}


#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#define mp make_pair
#define pb push_back
#define MAXN 0X800
#define MAX 0XFFFFFFF
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;

const int dx[] = {0,1,0,-1};
const int dy[] = {1,0,-1,0};

struct Node
{
	int n,v;
	bool operator < (const Node& a) const
	{
		return v<a.v;
	}
};

double ans;
int l,m,v,t,n,k,sum;
Node a[MAXN], b[MAXN];

int main()
{
	scanf("%d%d",&n,&k);
	l = m = sum = 0;
	for (int i=0; i<n; ++i)
	{
		scanf("%d%d",&v,&t);
		sum += v;
		if (t==1)
		{
			a[m].v = v;
			a[m++].n = i+1;
		}
		else
		{
			b[l].v = v;
			b[l++].n = i+1;
		}
	}
	sort(a,a+m);
	sort(b,b+l);
	ans = 0;
	if (m>=k)
	{
		for (int i=1; i<k; ++i)	ans += a[m-k+i].v/2.0;
		if (l>0)	ans += min(b[0].v,a[0].v)/2.0;
		else	ans += a[0].v/2.0;
		ans = sum-ans;
		printf("%.1f\n",ans);
		printf("%d",n-(k-1));
		for (int i=0; i<l; ++i)
			printf(" %d",b[i].n);
		for (int i=0; i<=m-k; ++i)
			printf(" %d",a[i].n);
		printf("\n");
		for (int i=1; i<k; ++i)
			printf("1 %d\n",a[m-k+i].n);
	}
	else
	{
		for (int i=0; i<m; ++i)	ans += a[i].v/2.0;
		ans = sum-ans;
		printf("%.1f\n",ans);
		for (int i=0; i<m; ++i)
			printf("1 %d\n",a[i].n);
		for (int i=m; i<k-1; ++i)
			printf("1 %d\n",b[i-m].n);
		printf("%d",n-k+1);
		for (int i=k-m-1; i<l; ++i)
			printf(" %d",b[i].n);
		printf("\n");
	}

	return 0;
}


#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#define mp make_pair
#define pb push_back
#define MAXN 0X800
#define MAX 0XFFFFFFF
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;

const int dx[] = {0,1,0,-1};
const int dy[] = {1,0,-1,0};

struct Node
{
	int n,v;
	bool operator < (const Node& a) const
	{
		return v<a.v;
	}
};

LL sum;
double ans;
int l,m,v,t,n,k;
Node a[MAXN], b[MAXN];

int main()
{
	scanf("%d%d",&n,&k);
	l = m = sum = 0;
	for (int i=0; i<n; ++i)
	{
		scanf("%d%d",&v,&t);
		sum += v;
		if (t==1)
		{
			a[m].v = v;
			a[m++].n = i+1;
		}
		else
		{
			b[l].v = v;
			b[l++].n = i+1;
		}
	}
	printf("%I64d\n",sum);
	sort(a,a+m);
	sort(b,b+l);
	ans = 0;
	if (m>=k)
	{
		for (int i=1; i<k; ++i)	ans += a[m-k+i].v/2.0;
		if (l>0)	ans += min(b[0].v,a[0].v)/2.0;
		else	ans += a[0].v/2.0;
		ans = sum-ans;
		printf("%.1f\n",ans);
		printf("%d",n-(k-1));
		for (int i=0; i<l; ++i)
			printf(" %d",b[i].n);
		for (int i=0; i<=m-k; ++i)
			printf(" %d",a[i].n);
		printf("\n");
		for (int i=1; i<k; ++i)
			printf("1 %d\n",a[m-k+i].n);
	}
	else
	{
		for (int i=0; i<m; ++i)	ans += a[i].v/2.0;
		ans = sum-ans;
		printf("%.1f\n",ans);
		for (int i=0; i<m; ++i)
			printf("1 %d\n",a[i].n);
		for (int i=m; i<k-1; ++i)
			printf("1 %d\n",b[i-m].n);
		printf("%d",n-k+1);
		for (int i=k-m-1; i<l; ++i)
			printf(" %d",b[i].n);
		printf("\n");
	}

	return 0;
}


#include <cmath>
#include <ctime>
#include <iostream>
#include <string>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <cctype>
#include <stack>
using namespace std;

typedef long long int int64;

#define EPS 10e-9
#define INF 0x3f3f3f3f
#define MAXN 1500

vector<pair<int, int> > stool;
vector<pair<int, int> > pencil;

vector<int> car[MAXN];

int main()
{
	int n, k;
	scanf("%d %d", &n, &k);

	stool.clear();
	pencil.clear();
	for (int i = 0; i < k; i++) car[i].clear();

	pair<int, int> menor;
	menor.second = INF;
	for (int i = 0; i < n; i++) {
		int c, t;
		scanf("%d %d", &c, &t);
		if (t == 1) {
			stool.push_back(make_pair(i, c));
		}
		else {
			pencil.push_back(make_pair(i, c));
		}
		if (c < menor.second) {
			menor = make_pair(i, c);
		}
	}
	sort(stool.begin(), stool.end());
	double res = 0;
	int tam = stool.size();
	if (tam >= k) {
		for (int i = 0; i < k-1; i++) {
			res = res + stool[tam-1-i].second * 0.5;
			car[i].push_back(stool[tam-1-i].first + 1);
		}
		res = res + menor.second * 0.5;
		for (int i = tam-k; i >= 0; i--) {
			car[k-1].push_back(stool[i].first + 1);
			if (stool[i].first != menor.first) {
				res = res + stool[i].second;
			}
		}
		for (int i = 0; i < pencil.size(); i++) {
			car[k-1].push_back(pencil[i].first + 1);
			if (pencil[i].first != menor.first) {
				res = res + pencil[i].second;
			}
		}
	}
	else {
		for (int i = 0; i < tam; i++) {
			res = res + stool[i].second * 0.5;
			car[i].push_back(stool[i].first + 1);
		}
		for (int j = 0; j < k - tam; j++) {
			car[j+tam].push_back(pencil[j].first + 1);
			res = res + pencil[j].second;
		}
		for (int j = k-tam; j < pencil.size(); j++) {
			car[tam].push_back(pencil[j].first + 1);
			res = res + pencil[j].second;
		}
	}

	printf("%.1lf\n", res);
	for (int i = 0; i < k; i++) {
		printf("%d", (int) car[i].size());
		for (int j = 0; j < car[i].size(); j++) {
			printf(" %d", car[i][j]);
		}
		printf("\n");
	}
	return 0;
}


#include <cmath>
#include <ctime>
#include <iostream>
#include <string>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <cctype>
#include <stack>
using namespace std;

typedef long long int int64;

#define EPS 10e-9
#define INF 0x3f3f3f3f
#define MAXN 1500

vector<pair<int, int> > stool;
vector<pair<int, int> > pencil;

vector<int> car[MAXN];

bool comp(pair<int, int> a, pair<int, int> b) {
	return a.second < b.second;
}

int main()
{
	int n, k;
	scanf("%d %d", &n, &k);

	stool.clear();
	pencil.clear();
	for (int i = 0; i < k; i++) car[i].clear();

	pair<int, int> menor;
	menor.second = INF;
	for (int i = 0; i < n; i++) {
		int c, t;
		scanf("%d %d", &c, &t);
		if (t == 1) {
			stool.push_back(make_pair(i, c));
		}
		else {
			pencil.push_back(make_pair(i, c));
		}
		if (c < menor.second) {
			menor = make_pair(i, c);
		}
	}
	sort(stool.begin(), stool.end(), comp);
	double res = 0;
	int tam = stool.size();
	if (tam >= k) {
		for (int i = 0; i < k-1; i++) {
			res = res + stool[tam-1-i].second * 0.5;
			car[i].push_back(stool[tam-1-i].first + 1);
		}
		res = res + menor.second * 0.5;
		for (int i = tam-k; i >= 0; i--) {
			car[k-1].push_back(stool[i].first + 1);
			if (stool[i].first != menor.first) {
				res = res + stool[i].second;
			}
		}
		for (int i = 0; i < pencil.size(); i++) {
			car[k-1].push_back(pencil[i].first + 1);
			if (pencil[i].first != menor.first) {
				res = res + pencil[i].second;
			}
		}
	}
	else {
		for (int i = 0; i < tam; i++) {
			res = res + stool[i].second * 0.5;
			car[i].push_back(stool[i].first + 1);
		}
		for (int j = 0; j < k - tam; j++) {
			car[j+tam].push_back(pencil[j].first + 1);
			res = res + pencil[j].second;
		}
		for (int j = k-tam; j < pencil.size(); j++) {
			car[tam].push_back(pencil[j].first + 1);
			res = res + pencil[j].second;
		}
	}

	printf("%.1lf\n", res);
	for (int i = 0; i < k; i++) {
		printf("%d", (int) car[i].size());
		for (int j = 0; j < car[i].size(); j++) {
			printf(" %d", car[i][j]);
		}
		printf("\n");
	}
	return 0;
}


#include <cmath>
#include <ctime>
#include <iostream>
#include <string>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <cctype>
#include <stack>
using namespace std;

typedef long long int int64;

#define EPS 10e-9
#define INF 0x3f3f3f3f
#define MAXN 1500

vector<pair<int, int> > stool;
vector<pair<int, int> > pencil;

vector<int> car[MAXN];

bool comp(pair<int, int> a, pair<int, int> b) {
	if (a.second == b.second) return a.first < b.first;
	return a.second < b.second;
}

int main()
{
	int n, k;
	scanf("%d %d", &n, &k);

	stool.clear();
	pencil.clear();
	for (int i = 0; i < k; i++) car[i].clear();

	pair<int, int> menor;
	menor.second = INF;
	for (int i = 0; i < n; i++) {
		int c, t;
		scanf("%d %d", &c, &t);
		if (t == 1) {
			stool.push_back(make_pair(i, c));
		}
		else {
			pencil.push_back(make_pair(i, c));
		}
		if (c < menor.second) {
			menor = make_pair(i, c);
		}
	}
	sort(stool.begin(), stool.end(), comp);
	double res = 0;
	int tam = stool.size();
	if (tam >= k) {
		for (int i = 0; i < k-1; i++) {
			res = res + stool[tam-1-i].second * 0.5;
			car[i].push_back(stool[tam-1-i].first + 1);
		}
		res = res + menor.second * 0.5;
		for (int i = tam-k; i >= 0; i--) {
			car[k-1].push_back(stool[i].first + 1);
			if (stool[i].first != menor.first) {
				res = res + stool[i].second;
			}
		}
		for (int i = 0; i < pencil.size(); i++) {
			car[k-1].push_back(pencil[i].first + 1);
			if (pencil[i].first != menor.first) {
				res = res + pencil[i].second;
			}
		}
	}
	else {
		for (int i = 0; i < tam; i++) {
			res = res + stool[i].second * 0.5;
			car[i].push_back(stool[i].first + 1);
		}
		for (int j = 0; j < k - tam; j++) {
			car[j+tam].push_back(pencil[j].first + 1);
			res = res + pencil[j].second;
		}
		for (int j = k-tam; j < pencil.size(); j++) {
			car[tam].push_back(pencil[j].first + 1);
			res = res + pencil[j].second;
		}
	}

	printf("%.1lf\n", res);
	for (int i = 0; i < k; i++) {
		printf("%d", (int) car[i].size());
		for (int j = 0; j < car[i].size(); j++) {
			printf(" %d", car[i][j]);
		}
		printf("\n");
	}
	return 0;
}


/*
 * File:   main.cpp
 * Author: liuyubo
 *
 * Created on March 11, 2012, 11:29 PM
 */

#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cctype>

#include <utility>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <queue>
#include <map>

using namespace std;

#define INF 2000000000

void loadData( void );
double proc( void );
void printRes( double );

typedef struct Item{
    int c,t,index;
}item;

typedef struct Cart{
    int stoolIndex;
    int minPrice;
    vector<item> pencils;
    vector<bool> inCart;
}cart;

int n,k;
double sum;
item items[1000];

vector<cart> carts;

bool icmp( const item &ia , const item &ib );
double calcPrice( void );
void unionCarts( void );
void seperateCarts( void );

bool lyb_debug = false;

void printCarts( void );

int main(int argc, char** argv) {

    loadData();
    printRes( proc() );

    return 0;
}

void printCarts( void ){

    printf("== carts size:%d k:%d ==\n",carts.size(),k);
    for( int i = 0 ; i < carts.size() ; i ++ ){
        printf("* stoolIndex:%d minPrice:%d pencils:",carts[i].stoolIndex,carts[i].minPrice);
        for( int j = 0 ; j < carts[i].pencils.size() ; j ++ )
            if( carts[i].inCart[j] )
                printf("%d ",carts[i].pencils[j].index);
        printf("\n");
    }

    return;
}

double calcPrice( void ){

    double res = sum;
    for( int i = 0 ; i < carts.size() ; i ++ )
        res -= (double)( carts[i].stoolIndex == -1 ? 0 : carts[i].minPrice )/2.0;
    return res;
}

void unionCarts( void ){

    for( int i = carts.size() - 1 ; i >= k ; i -- ){

        for( int j = 0 ; j < carts[i].pencils.size() ; j ++ ){
            carts[k-1].pencils.push_back( carts[i].pencils[j] );
            carts[k-1].inCart.push_back( true );
            carts[k-1].minPrice = min( carts[k-1].minPrice , carts[i].pencils[j].c );
        }
    }

    while( carts.size() != k )
        carts.pop_back();
    return;
}

void seperateCarts( void ){

    for( int i = 0 ; ; i ++ )
        for( int j = 0 ; j < carts[i].pencils.size() ; j ++ ){

            cart newCart;
            newCart.stoolIndex = -1;
            newCart.minPrice = carts[i].pencils[j].c;
            newCart.pencils.clear();
            newCart.inCart.clear();

            newCart.pencils.push_back( carts[i].pencils[j] );
            newCart.inCart.push_back( true );

            carts.push_back( newCart );

            carts[i].inCart[j] = false;

            if( carts.size() == k )
                return;
        }

    return;
}

double proc( void ){

    sort( items , items + n , icmp );

    carts.clear();
    int start = 0;

    int stoolIndex = -1;
    for( int i = start; i <= n ; ){

        if( i < n && items[i].t == 1 )
            stoolIndex = items[i].index;
        if( i >= n && start >= n )
            break;
        if( i == n || items[i].t == 1 ){

            cart newCart;
            newCart.stoolIndex = stoolIndex;
            newCart.minPrice = ( stoolIndex == -1 ? INF : items[stoolIndex].c );
            newCart.pencils.clear();
            newCart.inCart.clear();
            for( int j = start ; j <= min( n-1 , i ) ; j ++ ){
                if( items[j].index != stoolIndex ){
                    newCart.pencils.push_back( items[j] );
                    newCart.inCart.push_back( true );
                    newCart.minPrice = min( newCart.minPrice , items[j].c );
                }
            }

            carts.push_back( newCart );

            start = i + 1;
            i = start;

            stoolIndex = -1;
        }
        else
            i ++;
    }

    if( lyb_debug ){
        printf("After initial seperation:\n");
        printCarts();
    }

    if( k == carts.size() )
        return calcPrice();
    else if( k < carts.size() )
        unionCarts();
    else
        seperateCarts();

    return calcPrice();
}

bool icmp( const item &ia , const item &ib ){
    return ia.c > ib.c;
}

void loadData( void ){

    scanf("%d%d",&n,&k);

    sum = 0.0;
    for( int i = 0 ; i < n ; i ++ ){
        scanf("%d%d",&items[i].c,&items[i].t);
        items[i].index = i;
        sum += (double)items[i].c;
    }
    return;
}

void printRes( double res ){

    printf("%.1lf\n",res);
    for( int i = 0 ; i < carts.size() ; i ++ ){
        printf("%d",(int)carts[i].pencils.size() + ( carts[i].stoolIndex == -1 ? 0 : 1 ) );
        if( carts[i].stoolIndex != -1 )
            printf(" %d",carts[i].stoolIndex+1);
        for( int j = 0 ; j < carts[i].pencils.size() ; j ++ )
            if( carts[i].inCart[j] )
                printf(" %d",carts[i].pencils[j].index+1);
        printf("\n");
    }
    return;
}