#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<set>
#include<vector>
using namespace std;
#define maxn 100010
struct node{
	double p;
	int id,k;
}cart[maxn];
int cmp(node a,node b)
{
	if(a.k!=b.k) return a.k<b.k;
	return a.p>b.p;
}
double minn;
vector<int>vec[1010];
inline int min(int a,int b){ return a<b?b:a; }
int main()
{
	int n,k,i,j,cnt; double tot,tmp;
	while(scanf("%d%d",&n,&k)!=EOF){
		tot=0; cnt=0;
		for(i=0;i<n;i++){
			scanf("%lf%d",&cart[i].p,&cart[i].k);
			tot+=cart[i].p;
		    cart[i].id=i+1;
            if(cart[i].k==1)
                cnt++;
	    }
		minn=100000000000.0;
		sort(cart,cart+n,cmp);
		for(i=0;i<1000;i++)
			vec[i].clear();
		if(cnt<k){
			for(int i=0;i<k-1;++i){
            vec[i].push_back(cart[i].id);
            if(i<cnt)
                tot-=(cart[i].p/2);
        }
        for(int i=k-1;i<n;++i)
            vec[k-1].push_back(cart[i].id);
		}else{
			for(int i=0;i<k-1;++i){
				vec[i].push_back(cart[i].id);
				tot-=(cart[i].p/2);
			}
			for(int i=k-1;i<n;++i){
				vec[k-1].push_back(cart[i].id);
				minn=min(minn,cart[i].p);
			}
			tot-=(minn/2);
		}
		printf("%.01lf\n",tot);
		for(int i=0;i<k;++i){
			printf("%d",vec[i].size());
			for(int j=0;j<vec[i].size();++j)
				printf(" %d",vec[i][j]);
			printf("\n");
		}
	}
    return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<set>
#include<vector>
using namespace std;
#define maxn 1010
int n,m;
struct node{
    double p;
    int id,k;
}cart[maxn];
int cmp(node a,node b)
{
    if(a.k!=b.k) return a.k<b.k;
    return a.p>b.p;
}
vector<int>vec[1010];
int main()
{
    int i,j,cnt; double minn,tot,tt,ans;
    while(scanf("%d%d",&n,&m)!=EOF){
        cnt=0; minn=1000000000.0; tot=0.0; tt=0.0;
        for(i=0;i<n;i++){
            scanf("%lf%d",&cart[i].p,&cart[i].k);
            cart[i].id=i; if(cart[i].k==1) cnt++,tt+=cart[i].p; else tot+=cart[i].p;
            minn=cart[i].p>minn?minn:cart[i].p;
        }
        sort(cart,cart+n,cmp);
        for(i=0;i<n;i++) vec[i].clear();
        if(cnt<m){
            for(i=0;i<m-1;i++){
                vec[i].push_back(cart[i].id);
            }
            for(;i<n;i++){
                vec[m-1].push_back(cart[i].id);
            }
            ans=(tt/2)+tot;
        }else{
            double tmp=0,ttmp=0;
            for(i=0;i<m-1;i++){
                vec[i].push_back(cart[i].id),tmp+=cart[i].p;
            }
            for(;i<n;i++){
                vec[m-1].push_back(cart[i].id),ttmp+=cart[i].p;
            }
            ans=(tmp+minn)/2+(ttmp-minn);
        }
        printf("%.01lf\n",ans);
        for(i=0;i<m;i++){
            printf("%d",vec[i].size());
            for(j=0;j<vec[i].size();j++){
                printf(" %d",vec[i][j]+1);
            }
            printf("\n");
        }
    }
    return 0;
}


#include<stdio.h>
#include<string.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<stdlib.h>
#include<math.h>
#include<queue>
using namespace std;
struct node
{
    double x;
    int i;
}a[1005],b[1005];
bool cmp(node a,node b)
{
    return a.x<b.x;
}
int main()
{
    int i,j,n,k,ni,nj,y;
    double ans,x,mm;
    scanf("%d%d",&n,&k);
    ni=nj=0;
    for(i=0;i<n;++i)
    {
        scanf("%lf%d",&x,&y);
        if(y==1)
        {
            a[ni].i=i+1;
            a[ni++].x=x;
        }
        else
        {
            b[nj].i=i+1;
            b[nj++].x=x;
        }
    }
    sort(a,a+ni,cmp);
    sort(b,b+nj,cmp);
    if(ni<k)
    {
        ans=0;
        for(i=0;i<ni;++i)
            ans+=a[i].x;
        ans/=2;
        for(j=0;j<nj;++j)
            ans+=b[j].x;
        printf("%.1lf\n",ans);
        for(i=0;i<ni;++i)
            printf("1 %d\n",a[i].i);
        for(j=0;i<k-1;++i,++j)
            printf("1 %d\n",b[j].i);
        printf("%d",n-k+1);
        for(;j<nj;++j)
            printf(" %d",b[j].i);
        printf("\n");
    }
    else
    {
        ans=0;
        mm=min(a[0].x,b[0].x);
        for(i=ni-1,j=0;j<k-1;--i,++j)
        {
            ans+=a[i].x;
        }
        ans/=2;
        for(;i>=0;--i)
            ans+=a[i].x;
        for(j=0;j<nj;++j)
            ans+=b[j].x;
        mm/=2;
        ans-=mm;
        printf("%.1lf\n",ans);
        for(i=ni-1,j=0;j<k-1;--i,++j)
        {
            printf("1 %d\n",a[i].i);
        }
        printf("%d",n-k+1);
        for(;i>=0;--i)
            printf(" %d",a[i].i);
        for(j=0;j<nj;++j)
            printf(" %d",b[j].i);
        printf("\n");
    }
}


#include<stdio.h>
#include<string.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<stdlib.h>
#include<math.h>
#include<queue>
using namespace std;
struct node
{
    double x;
    int i;
}a[1005],b[1005];
bool cmp(node a,node b)
{
    return a.x<b.x;
}
int main()
{
    int i,j,n,k,ni,nj,y,mm;
    double ans,x;
    scanf("%d%d",&n,&k);
    ni=nj=0;
    for(i=0;i<n;++i)
    {
        scanf("%lf%d",&x,&y);
        if(y==1)
        {
            a[ni].i=i+1;
            a[ni++].x=x;
        }
        else
        {
            b[nj].i=i+1;
            b[nj++].x=x;
        }
    }
    sort(a,a+ni,cmp);
    sort(b,b+nj,cmp);
    if(ni<k)
    {
        ans=0;
        for(i=0;i<ni;++i)
            ans+=a[i].x;
        ans/=2;
        for(j=0;j<nj;++j)
            ans+=b[j].x;
        printf("%.1lf\n",ans);
        for(i=0;i<ni;++i)
            printf("1 %d\n",a[i].i);
        for(j=0;i<k-1;++i,++j)
            printf("1 %d\n",b[j].i);
        printf("%d",n-k+1);
        for(;j<nj;++j)
            printf(" %d",b[j].i);
        printf("\n");
    }
    else
    {
        ans=0;
        mm=min(a[0].x,b[0].x);
        for(i=ni-1,j=0;j<k-1;--i,++j)
        {
            ans+=a[i].x;
        }
        ans/=2;
        for(;i>=0;--i)
            ans+=a[i].x;
        for(j=0;j<nj;++j)
            ans+=b[j].x;
        mm/=2;
        ans-=mm;
        printf("%.1lf\n",ans);
        for(i=ni-1,j=0;j<k-1;--i,++j)
        {
            printf("1 %d\n",a[i].i);
        }
        printf("%d",n-k+1);
        for(;i>=0;--i)
            printf(" %d",a[i].i);
        for(j=0;j<nj;++j)
            printf(" %d",b[j].i);
        printf("\n");
    }
}


#include<stdio.h>
#include<string.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<stdlib.h>
#include<math.h>
#include<queue>
using namespace std;
struct node
{
    double x;
    int i;
}a[1005],b[1005];
bool cmp(node a,node b)
{
    return a.x<b.x;
}
int main()
{
    int i,j,n,k,ni,nj,y;
    double ans,x,mm;
    scanf("%d%d",&n,&k);
    ni=nj=0;
    for(i=0;i<n;++i)
    {
        scanf("%lf%d",&x,&y);
        if(y==1)
        {
            a[ni].i=i+1;
            a[ni++].x=x;
        }
        else
        {
            b[nj].i=i+1;
            b[nj++].x=x;
        }
    }
    sort(a,a+ni,cmp);
    sort(b,b+nj,cmp);
    if(ni<k)
    {
        ans=0;
        for(i=0;i<ni;++i)
            ans+=a[i].x;
        ans/=2;
        for(j=0;j<nj;++j)
            ans+=b[j].x;
        printf("%.1lf\n",ans);
        for(i=0;i<ni;++i)
            printf("1 %d\n",a[i].i);
        for(j=0;i<k-1;++i,++j)
            printf("1 %d\n",b[j].i);
        printf("%d",n-k+1);
        for(;j<nj;++j)
            printf(" %d",b[j].i);
        printf("\n");
    }
    else
    {
        ans=0;
        if(ni==0)
            mm=b[0].x;
        else if(nj==0)
            mm=a[0].x;
        else
            mm=min(a[0].x,b[0].x);
        for(i=ni-1,j=0;j<k-1;--i,++j)
        {
            ans+=a[i].x;
        }
        ans/=2;
        for(;i>=0;--i)
            ans+=a[i].x;
        for(j=0;j<nj;++j)
            ans+=b[j].x;
        mm/=2;
        ans-=mm;
        printf("%.1lf\n",ans);
        for(i=ni-1,j=0;j<k-1;--i,++j)
        {
            printf("1 %d\n",a[i].i);
        }
        printf("%d",n-k+1);
        for(;i>=0;--i)
            printf(" %d",a[i].i);
        for(j=0;j<nj;++j)
            printf(" %d",b[j].i);
        printf("\n");
    }
}


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

struct stool
{
	int id,price;
};

struct pencil
{
	int id,price;
};

struct cart
{
	vector<int> stuff;
	bool discount;
	long long price;
};

bool cmp1(stool a,stool b)
{
	return a.price>b.price;
}

bool cmp2(pencil a,pencil b)
{
	return a.price>b.price;
}

stool A[1000];
pencil B[1000];
cart C[1000];
int p[1000];

int main()
{
	int N,K;
	cin >> N >> K;
	int t,price;
	int nA = 0;	//stools
	int nB = 0;	//pencils
	for(int i=0;i<N;i++)
	{
		cin >> price >> t;
		p[i] = price;
		if(t==1)
		{
			A[nA].id = i;
			A[nA++].price = price;
		}
		else
		{
			B[nB].id = i;
			B[nB++].price = price;
		}
	}
	for(int i=0;i<K;i++)
		C[i].discount = C[i].price = 0;
	sort(A,A+nA,cmp1);
	sort(B,B+nB,cmp2);
	for(int i=0;i<nA;i++)
	{
		if(i<K)
		{
			C[i].stuff.push_back(A[i].id);
			C[i].price += A[i].price;
			C[i].discount = 1;
		}
		else
		{
			C[K-1].stuff.push_back(A[i].id);
			C[K-1].price += A[i].price;
			C[K-1].discount = 1;
		}
	}
	if(nA>=K)
	{
		for(int i=0;i<nB;i++)
		{
			C[K-1].stuff.push_back(B[i].id);
			C[K-1].price += B[i].price;
		}
	}
	else
	{
		int j = nA;
		int i = 0;
		for(;j<K;j++,i++)
		{
			C[j].stuff.push_back(B[i].id);
			C[j].price += B[i].price;
		}
		for(;i<nB;i++)
		{
			C[K-1].stuff.push_back(B[i].id);
			C[K-1].price += B[i].price;
		}
	}
	for(int i=0;i<K;i++)
		sort(C[i].stuff.begin(),C[i].stuff.end());
	long long tot = 0;
	for(int i=0;i<K;i++)
	{
		tot += 10*C[i].price;
		if(C[i].discount)
			tot -= 5*p[C[i].stuff[0]];
	}
	cout << tot/10 << "." << tot%10 << endl;
	for(int i=0;i<K;i++)
	{
		cout << C[i].stuff.size();
		for(int j=0;j<C[i].stuff.size();j++)
			cout << " " << C[i].stuff[j]+1;
		cout << endl;
	}
}


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

struct stool
{
	long long id,price;
};

struct pencil
{
	long long id,price;
};

struct cart
{
	vector<int> stuff;
	bool discount;
	long long price;
};

bool cmp1(stool a,stool b)
{
	return a.price>b.price;
}

bool cmp2(pencil a,pencil b)
{
	return a.price>b.price;
}

stool A[1000];
pencil B[1000];
cart C[1000];
long long p[1000];

int main()
{
	int N,K;
	cin >> N >> K;
	int t,price;
	int nA = 0;	//stools
	int nB = 0;	//pencils
	for(int i=0;i<N;i++)
	{
		cin >> price >> t;
		p[i] = price;
		if(t==1)
		{
			A[nA].id = i;
			A[nA++].price = price;
		}
		else
		{
			B[nB].id = i;
			B[nB++].price = price;
		}
	}
	for(int i=0;i<K;i++)
		C[i].discount = C[i].price = 0;
	sort(A,A+nA,cmp1);
	sort(B,B+nB,cmp2);
	for(int i=0;i<nA;i++)
	{
		if(i<K)
		{
			C[i].stuff.push_back(A[i].id);
			C[i].price += A[i].price;
			C[i].discount = 1;
		}
		else
		{
			C[K-1].stuff.push_back(A[i].id);
			C[K-1].price += A[i].price;
			C[K-1].discount = 1;
		}
	}
	if(nA>=K)
	{
		for(int i=0;i<nB;i++)
		{
			C[K-1].stuff.push_back(B[i].id);
			C[K-1].price += B[i].price;
		}
	}
	else
	{
		int j = nA;
		int i = 0;
		for(;j<K;j++,i++)
		{
			C[j].stuff.push_back(B[i].id);
			C[j].price += B[i].price;
		}
		for(;i<nB;i++)
		{
			C[K-1].stuff.push_back(B[i].id);
			C[K-1].price += B[i].price;
		}
	}
	for(int i=0;i<K;i++)
		sort(C[i].stuff.begin(),C[i].stuff.end());
	long long tot = 0;
	for(int i=0;i<K;i++)
	{
		tot += 10*C[i].price;
		if(C[i].discount)
			tot -= 5*p[C[i].stuff[0]];
	}
	cout << tot/10 << "." << tot%10 << endl;
	for(int i=0;i<K;i++)
	{
		cout << C[i].stuff.size();
		for(int j=0;j<C[i].stuff.size();j++)
			cout << " " << C[i].stuff[j]+1;
		cout << endl;
	}
}


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

struct stool
{
	long long id,price;
};

struct pencil
{
	long long id,price;
};

struct cart
{
	vector<int> stuff;
	bool discount;
	long long price;
};

bool cmp1(stool a,stool b)
{
	return a.price>b.price;
}

bool cmp2(pencil a,pencil b)
{
	return a.price>b.price;
}

stool A[1000];
pencil B[1000];
cart C[1000];
long long p[1000];

bool cmp3(int a,int b)
{
	return p[a]<p[b];
}

int main()
{
	int N,K;
	cin >> N >> K;
	int t,price;
	int nA = 0;	//stools
	int nB = 0;	//pencils
	for(int i=0;i<N;i++)
	{
		cin >> price >> t;
		p[i] = price;
		if(t==1)
		{
			A[nA].id = i;
			A[nA++].price = price;
		}
		else
		{
			B[nB].id = i;
			B[nB++].price = price;
		}
	}
	for(int i=0;i<K;i++)
		C[i].discount = C[i].price = 0;
	sort(A,A+nA,cmp1);
	sort(B,B+nB,cmp2);
	for(int i=0;i<nA;i++)
	{
		if(i<K)
		{
			C[i].stuff.push_back(A[i].id);
			C[i].price += A[i].price;
			C[i].discount = 1;
		}
		else
		{
			C[K-1].stuff.push_back(A[i].id);
			C[K-1].price += A[i].price;
			C[K-1].discount = 1;
		}
	}
	if(nA>=K)
	{
		for(int i=0;i<nB;i++)
		{
			C[K-1].stuff.push_back(B[i].id);
			C[K-1].price += B[i].price;
		}
	}
	else
	{
		int j = nA;
		int i = 0;
		for(;j<K;j++,i++)
		{
			C[j].stuff.push_back(B[i].id);
			C[j].price += B[i].price;
		}
		for(;i<nB;i++)
		{
			C[K-1].stuff.push_back(B[i].id);
			C[K-1].price += B[i].price;
		}
	}
	for(int i=0;i<K;i++)
		sort(C[i].stuff.begin(),C[i].stuff.end(),cmp3);
	long long tot = 0;
	for(int i=0;i<K;i++)
	{
		tot += ((long long)10)*C[i].price;
		if(C[i].discount)
			tot -= ((long long)5)*p[C[i].stuff[0]];
	}
	cout << tot/10 << "." << tot%10 << endl;
	for(int i=0;i<K;i++)
	{
		cout << C[i].stuff.size();
		for(int j=0;j<C[i].stuff.size();j++)
			cout << " " << C[i].stuff[j]+1;
		cout << endl;
	}
}


#include <cmath>
#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
#include <map>

#define ReadInt(name) int name = 0; std::cin >> name;

template <class t>
std::map<t, size_t> countMap(const std::vector<t>& input)
{
    std::map<t, size_t> temp;
    for (size_t v = 0; v < input.size(); v++)
    {
        temp[input[v]] = 0;
    }
    for (size_t v = 0; v < input.size(); v++)
    {
        temp[input[v]]++;
    }
    return temp;
}

template <class t>
class vectorExt : public std::vector<t>
{
public:
    vectorExt() { }

    vectorExt(std::istream& in)
    {
        size_t count;
        std::cin >> count;
        for (size_t u = 0; u < count; u++)
        {
            t data;
            std::cin >> data;
            push_back(data);
        }
    }

    vectorExt(size_t count, std::istream& in)
    {
        for (size_t u = 0; u < count; u++)
        {
            t data;
            std::cin >> data;
            push_back(data);
        }
    }

    void sort()
    {
        std::sort(begin(), end());
    }

    size_t minIndex() const
    {
        size_t result = std::string::npos;
        if (!empty())
        {
            result = 0;
            t data = (*this)[0];
            for (size_t u = 1; u < size(); u++)
            {
                if ((*this)[u] < data)
                {
                    data = (*this)[u];
                    result = u;
                }
            }
        }
        return result;
    }

    t minValue() // can produce error on empty vector
    {
        return at(minIndex());
    }

    size_t maxIndex() const
    {
        size_t result = std::string::npos;
        if (!empty())
        {
            result = 0;
            t data = (*this)[0];
            for (size_t u = 1; u < size(); u++)
            {
                if ((*this)[u] > data)
                {
                    data = (*this)[u];
                    result = u;
                }
            }
        }
        return result;
    }

    t maxValue() // can produce error on empty vector
    {
        return at(maxIndex());
    }

    t sum(size_t startIdx = 0, size_t endIdx = std::string::npos)
    {
        t result;
        setZero(result);
        for (size_t u = startIdx; u < endIdx && u < size(); u++)
            result += (*this)[u];
        return result;
    }
};

struct InputRec
{
    int cost;
    int index;
    int type;
};

bool sortF(const InputRec& a, const InputRec& b)
{
    return a.cost > b.cost;
}

std::vector<InputRec > all;

int align(const std::vector<std::vector<int>>& data)
{
    int result = 0;
    for (size_t u = 0; u < data.size(); u++)
        if (data[u].size() > 0)
            result++;
    return result;
}

double cost(const std::vector<std::vector<int>>& data)
{
    double all_cost = 0.0;
    for (size_t u = 0; u < data.size(); u++)
    {
        double part_cost = 0;
        double discount_used = false;
        for (size_t v = 0; v < data[u].size(); v++)
        {
            part_cost += all[data[u][v]].cost;
            if (!discount_used && all[data[u][v]].type == 1)
            {
                double min_cost = all[data[u][0]].cost;
                for (size_t v1 = 0; v1 < data[u].size(); v1++)
                    if (all[data[u][v1]].cost < min_cost)
                        min_cost = all[data[u][v1]].cost;
                discount_used = true;
                part_cost -= min_cost / 2.0;
            }
        }
        all_cost += part_cost;
    }
    return all_cost;
}

int main(int argc, char* argv[])
{
    // 10^3 = 1000
    ReadInt(n);
    ReadInt(k);
    std::vector<InputRec > pencils;
    std::vector<InputRec > chairs;

    for (int u = 0; u < n; u++)
    {
        InputRec in;
        std::cin >> in.cost >> in.type;
        in.index = u;
        if (in.type == 1)
            chairs.push_back(in);
        else if (in.type == 2)
            pencils.push_back(in);
        all.push_back(in);
    }

    std::sort(chairs.begin(), chairs.end(), sortF);
    std::sort(pencils.begin(), pencils.end(), sortF);

    std::sort(all.begin(), all.end(), sortF);

    std::vector<std::vector<int> > buckets;
    buckets.resize(k);

    for (size_t u = 0; u < all.size(); u++)
    {
        std::vector<std::vector<int> > best;

        {
            std::vector<std::vector<int> > temp = buckets;
            temp[0].push_back(u);
            best = temp;
        }

        for (size_t placement = 0; placement < k; placement++)
        {
            std::vector<std::vector<int> > temp = buckets;
            temp[placement].push_back(u);
            if (cost(temp) < cost(best) ||
                fabs(cost(temp) - cost(best)) < 0.0001 && align(temp) > align(best))
                best = temp;
        }

        buckets = best;
    }

    //std::cout << cost(buckets) << std::endl;
    printf("%.1f\n", cost(buckets));
    for (int i = 0; i < buckets.size(); i++)
    {
        std::cout << buckets[i].size();
        for (int j = 0; j < buckets[i].size(); j++)
            std::cout << " " << (buckets[i][j] + 1);
        std::cout << std::endl;
    }

    return 0;
}


#include <cmath>
#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
#include <map>

#define ReadInt(name) int name = 0; std::cin >> name;

template <class t>
std::map<t, size_t> countMap(const std::vector<t>& input)
{
    std::map<t, size_t> temp;
    for (size_t v = 0; v < input.size(); v++)
    {
        temp[input[v]] = 0;
    }
    for (size_t v = 0; v < input.size(); v++)
    {
        temp[input[v]]++;
    }
    return temp;
}

template <class t>
class vectorExt : public std::vector<t>
{
public:
    vectorExt() { }

    vectorExt(std::istream& in)
    {
        size_t count;
        std::cin >> count;
        for (size_t u = 0; u < count; u++)
        {
            t data;
            std::cin >> data;
            push_back(data);
        }
    }

    vectorExt(size_t count, std::istream& in)
    {
        for (size_t u = 0; u < count; u++)
        {
            t data;
            std::cin >> data;
            push_back(data);
        }
    }

    void sort()
    {
        std::sort(begin(), end());
    }

    size_t minIndex() const
    {
        size_t result = std::string::npos;
        if (!empty())
        {
            result = 0;
            t data = (*this)[0];
            for (size_t u = 1; u < size(); u++)
            {
                if ((*this)[u] < data)
                {
                    data = (*this)[u];
                    result = u;
                }
            }
        }
        return result;
    }

    t minValue() // can produce error on empty vector
    {
        return at(minIndex());
    }

    size_t maxIndex() const
    {
        size_t result = std::string::npos;
        if (!empty())
        {
            result = 0;
            t data = (*this)[0];
            for (size_t u = 1; u < size(); u++)
            {
                if ((*this)[u] > data)
                {
                    data = (*this)[u];
                    result = u;
                }
            }
        }
        return result;
    }

    t maxValue() // can produce error on empty vector
    {
        return at(maxIndex());
    }

    t sum(size_t startIdx = 0, size_t endIdx = std::string::npos)
    {
        t result;
        setZero(result);
        for (size_t u = startIdx; u < endIdx && u < size(); u++)
            result += (*this)[u];
        return result;
    }
};

struct InputRec
{
    int cost;
    int index;
    int type;
};

bool sortF(const InputRec& a, const InputRec& b)
{
    return a.cost > b.cost;
}

std::vector<InputRec > all;

int align(const std::vector<std::vector<int>>& data)
{
    int result = 0;
    for (size_t u = 0; u < data.size(); u++)
        if (data[u].size() > 0)
            result++;
    return result;
}

double cost(const std::vector<std::vector<int>>& data)
{
    double all_cost = 0.0;
    for (size_t u = 0; u < data.size(); u++)
    {
        double part_cost = 0;
        double discount_used = false;
        for (size_t v = 0; v < data[u].size(); v++)
        {
            part_cost += all[data[u][v]].cost;
            if (!discount_used && all[data[u][v]].type == 1)
            {
                double min_cost = all[data[u][0]].cost;
                for (size_t v1 = 0; v1 < data[u].size(); v1++)
                    if (all[data[u][v1]].cost < min_cost)
                        min_cost = all[data[u][v1]].cost;
                discount_used = true;
                part_cost -= min_cost / 2.0;
            }
        }
        all_cost += part_cost;
    }
    return all_cost;
}

int main(int argc, char* argv[])
{
    // 10^3 = 1000
    ReadInt(n);
    ReadInt(k);
    std::vector<InputRec > pencils;
    std::vector<InputRec > chairs;

    for (int u = 0; u < n; u++)
    {
        InputRec in;
        std::cin >> in.cost >> in.type;
        in.index = u;
        if (in.type == 1)
            chairs.push_back(in);
        else if (in.type == 2)
            pencils.push_back(in);
        all.push_back(in);
    }

    std::sort(chairs.begin(), chairs.end(), sortF);
    std::sort(pencils.begin(), pencils.end(), sortF);

    std::sort(all.begin(), all.end(), sortF);

    std::vector<std::vector<int> > buckets;
    buckets.resize(k);

    for (size_t u = 0; u < all.size(); u++)
    {
        std::vector<std::vector<int> > best;

        {
            std::vector<std::vector<int> > temp = buckets;
            temp[0].push_back(u);
            best = temp;
        }

        for (size_t placement = 0; placement < k; placement++)
        {
            std::vector<std::vector<int> > temp = buckets;
            temp[placement].push_back(u);
            if (cost(temp) < cost(best) ||
                fabs(cost(temp) - cost(best)) < 0.0001 && align(temp) > align(best))
                best = temp;
        }

        buckets = best;
    }

    //std::cout << cost(buckets) << std::endl;
    printf("%.1f\n", cost(buckets));
    for (int i = 0; i < buckets.size(); i++)
    {
        std::cout << buckets[i].size();
        for (int j = 0; j < buckets[i].size(); j++)
            std::cout << " " << (all[buckets[i][j]].index + 1);
        std::cout << std::endl;
    }

    return 0;
}


#include <cmath>
#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
#include <map>

#define ReadInt(name) int name = 0; std::cin >> name;

template <class t>
std::map<t, size_t> countMap(const std::vector<t>& input)
{
    std::map<t, size_t> temp;
    for (size_t v = 0; v < input.size(); v++)
    {
        temp[input[v]] = 0;
    }
    for (size_t v = 0; v < input.size(); v++)
    {
        temp[input[v]]++;
    }
    return temp;
}

template <class t>
class vectorExt : public std::vector<t>
{
public:
    vectorExt() { }

    vectorExt(std::istream& in)
    {
        size_t count;
        std::cin >> count;
        for (size_t u = 0; u < count; u++)
        {
            t data;
            std::cin >> data;
            push_back(data);
        }
    }

    vectorExt(size_t count, std::istream& in)
    {
        for (size_t u = 0; u < count; u++)
        {
            t data;
            std::cin >> data;
            push_back(data);
        }
    }

    void sort()
    {
        std::sort(begin(), end());
    }

    size_t minIndex() const
    {
        size_t result = std::string::npos;
        if (!empty())
        {
            result = 0;
            t data = (*this)[0];
            for (size_t u = 1; u < size(); u++)
            {
                if ((*this)[u] < data)
                {
                    data = (*this)[u];
                    result = u;
                }
            }
        }
        return result;
    }

    t minValue() // can produce error on empty vector
    {
        return at(minIndex());
    }

    size_t maxIndex() const
    {
        size_t result = std::string::npos;
        if (!empty())
        {
            result = 0;
            t data = (*this)[0];
            for (size_t u = 1; u < size(); u++)
            {
                if ((*this)[u] > data)
                {
                    data = (*this)[u];
                    result = u;
                }
            }
        }
        return result;
    }

    t maxValue() // can produce error on empty vector
    {
        return at(maxIndex());
    }

    t sum(size_t startIdx = 0, size_t endIdx = std::string::npos)
    {
        t result;
        setZero(result);
        for (size_t u = startIdx; u < endIdx && u < size(); u++)
            result += (*this)[u];
        return result;
    }
};

struct InputRec
{
    int cost;
    int index;
    int type;
};

bool sortF(const InputRec& a, const InputRec& b)
{
    return a.cost > b.cost;
}

std::vector<InputRec > all;

class MyData : public std::vector<std::vector<int> >
{
public:
    std::vector<double> costs;
    std::vector<int> costs_valid;
    std::vector<int> discounts_on;
};

int align(const MyData& data, int placement)
{
    if (data[placement].empty())
        return 1;
    else
        return 0;
}

double cost(MyData& data)
{
    double all_cost = 0.0;
    for (size_t u = 0; u < data.size(); u++)
    {
        if (data[u].size() == 0)
            continue;

        double part_cost = 0;

        if (data.costs_valid[u] == 1)
        {
            part_cost = data.costs[u];
        }
        else
        {
            bool discount_on = 0;

            int min_cost = all[data[u][0]].cost;
            for (size_t v1 = 0; v1 < data[u].size(); v1++)
                if (all[data[u][v1]].cost < min_cost)
                    min_cost = all[data[u][v1]].cost;

            for (size_t v = 0; v < data[u].size(); v++)
            {
                part_cost += all[data[u][v]].cost;
                if ((discount_on == 0) && all[data[u][v]].type == 1)
                {
                    discount_on = min_cost;
                    part_cost -= (double) min_cost / 2.0;
                }
            }

            data.costs[u] = part_cost;
            data.costs_valid[u] = 1;
            data.discounts_on[u] = discount_on;
        }

        all_cost += part_cost;
    }
    return all_cost;
}

double cost_fixup(double base_cost, MyData& data, int placement, int idx)
{
    double result = base_cost;

    double part_cost = 0.0;

    if (data.discounts_on[placement] > all[idx].cost )
    {
        part_cost = all[idx].cost;
    }
    else
    {
        result -= data.costs[placement];

        bool discount_used = false;

        std::vector<int> temp = data[placement];
        temp.push_back(idx);

        double min_cost = all[temp[0]].cost;
        for (size_t v1 = 0; v1 < temp.size(); v1++)
            if (all[temp[v1]].cost < min_cost)
                min_cost = all[temp[v1]].cost;

        for (size_t v = 0; v < temp.size(); v++)
        {
            part_cost += all[temp[v]].cost;
            if (!discount_used && all[temp[v]].type == 1)
            {
                discount_used = true;
                part_cost -= min_cost / 2.0;
            }
        }
    }

    return result + part_cost;
}

int main(int argc, char* argv[])
{
    // 10^3 = 1000
    ReadInt(n);
    ReadInt(k);
    //int n = 1000, k = 1000;

    std::vector<InputRec > pencils;
    std::vector<InputRec > chairs;

    for (int u = 0; u < n; u++)
    {
        InputRec in;
        std::cin >> in.cost >> in.type;
        //in.cost = 1;
        //in.type = 2;

        in.index = u;
        if (in.type == 1)
            chairs.push_back(in);
        else if (in.type == 2)
            pencils.push_back(in);
        all.push_back(in);
    }

    std::sort(chairs.begin(), chairs.end(), sortF);
    std::sort(pencils.begin(), pencils.end(), sortF);

    std::sort(all.begin(), all.end(), sortF);

    MyData buckets;
    buckets.resize(k);
    for (size_t u = 0; u < k; u++)
    {
        buckets.costs.push_back( 0.0);
        buckets.costs_valid.push_back( 0);
        buckets.discounts_on.push_back(0);
    }

    for (size_t u = 0; u < all.size(); u++)
    {
        //printf("%u\n", u);

        double base_cost = cost(buckets);

        int best_placement = 0;
        double best_cost = cost_fixup(base_cost, buckets, 0, u);

        for (size_t placement = 0; placement < k; placement++)
        {
            double t = cost_fixup(base_cost, buckets, placement, u);

            if (t < best_cost ||
                fabs(t - best_cost) < 0.0001
                  && align(buckets, placement) > align(buckets, best_placement))
            {
                best_placement = placement;
                best_cost = t;
            }
        }

        buckets[best_placement].push_back(u);
        buckets.costs_valid[best_placement] = false;
    }

    //std::cout << cost(buckets) << std::endl;
    printf("%.1f\n", cost(buckets));
    for (int i = 0; i < buckets.size(); i++)
    {
        std::cout << buckets[i].size();
        for (int j = 0; j < buckets[i].size(); j++)
            std::cout << " " << (all[buckets[i][j]].index + 1);
        std::cout << std::endl;
    }

    return 0;
}


#include <cmath>
#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
#include <map>

#define ReadInt(name) int name = 0; std::cin >> name;

template <class t>
std::map<t, size_t> countMap(const std::vector<t>& input)
{
    std::map<t, size_t> temp;
    for (size_t v = 0; v < input.size(); v++)
    {
        temp[input[v]] = 0;
    }
    for (size_t v = 0; v < input.size(); v++)
    {
        temp[input[v]]++;
    }
    return temp;
}

template <class t>
class vectorExt : public std::vector<t>
{
public:
    vectorExt() { }

    vectorExt(std::istream& in)
    {
        size_t count;
        std::cin >> count;
        for (size_t u = 0; u < count; u++)
        {
            t data;
            std::cin >> data;
            push_back(data);
        }
    }

    vectorExt(size_t count, std::istream& in)
    {
        for (size_t u = 0; u < count; u++)
        {
            t data;
            std::cin >> data;
            push_back(data);
        }
    }

    void sort()
    {
        std::sort(begin(), end());
    }

    size_t minIndex() const
    {
        size_t result = std::string::npos;
        if (!empty())
        {
            result = 0;
            t data = (*this)[0];
            for (size_t u = 1; u < size(); u++)
            {
                if ((*this)[u] < data)
                {
                    data = (*this)[u];
                    result = u;
                }
            }
        }
        return result;
    }

    t minValue() // can produce error on empty vector
    {
        return at(minIndex());
    }

    size_t maxIndex() const
    {
        size_t result = std::string::npos;
        if (!empty())
        {
            result = 0;
            t data = (*this)[0];
            for (size_t u = 1; u < size(); u++)
            {
                if ((*this)[u] > data)
                {
                    data = (*this)[u];
                    result = u;
                }
            }
        }
        return result;
    }

    t maxValue() // can produce error on empty vector
    {
        return at(maxIndex());
    }

    t sum(size_t startIdx = 0, size_t endIdx = std::string::npos)
    {
        t result;
        setZero(result);
        for (size_t u = startIdx; u < endIdx && u < size(); u++)
            result += (*this)[u];
        return result;
    }
};

struct InputRec
{
    int cost;
    int index;
    int type;
};

bool sortF(const InputRec& a, const InputRec& b)
{
    return a.cost > b.cost;
}

std::vector<InputRec > all;

int align(const std::vector<std::vector<int>>& data)
{
    int result = 0;
    for (size_t u = 0; u < data.size(); u++)
        if (data[u].size() > 0)
            result++;
    return result;
}

double cost(const std::vector<std::vector<int>>& data)
{
    double all_cost = 0.0;
    for (size_t u = 0; u < data.size(); u++)
    {
        if (data[u].size() == 0)
            continue;

        double part_cost = 0;
        double discount_used = false;

        double min_cost = all[data[u][0]].cost;
        for (size_t v1 = 0; v1 < data[u].size(); v1++)
            if (all[data[u][v1]].cost < min_cost)
                min_cost = all[data[u][v1]].cost;

        for (size_t v = 0; v < data[u].size(); v++)
        {
            part_cost += all[data[u][v]].cost;
            if (!discount_used && all[data[u][v]].type == 1)
            {
                discount_used = true;
                part_cost -= min_cost / 2.0;
            }
        }
        all_cost += part_cost;
    }
    return all_cost;
}

int main(int argc, char* argv[])
{
    // 10^3 = 1000
    ReadInt(n);
    ReadInt(k);
    std::vector<InputRec > pencils;
    std::vector<InputRec > chairs;

    for (int u = 0; u < n; u++)
    {
        InputRec in;
        std::cin >> in.cost >> in.type;
        in.index = u;
        if (in.type == 1)
            chairs.push_back(in);
        else if (in.type == 2)
            pencils.push_back(in);
        all.push_back(in);
    }

    std::sort(chairs.begin(), chairs.end(), sortF);
    std::sort(pencils.begin(), pencils.end(), sortF);

    std::sort(all.begin(), all.end(), sortF);

    std::vector<std::vector<int> > buckets;
    buckets.resize(k);

    for (size_t u = 0; u < all.size(); u++)
    {
        std::vector<std::vector<int> > best;

        {
            std::vector<std::vector<int> > temp = buckets;
            temp[0].push_back(u);
            best = temp;
        }

        for (size_t placement = 0; placement < k; placement++)
        {
            std::vector<std::vector<int> > temp = buckets;
            temp[placement].push_back(u);
            if (cost(temp) < cost(best) ||
                fabs(cost(temp) - cost(best)) < 0.0001 && align(temp) > align(best))
                best = temp;
        }

        buckets = best;
    }

    //std::cout << cost(buckets) << std::endl;
    printf("%.1f\n", cost(buckets));
    for (int i = 0; i < buckets.size(); i++)
    {
        std::cout << buckets[i].size();
        for (int j = 0; j < buckets[i].size(); j++)
            std::cout << " " << (all[buckets[i][j]].index + 1);
        std::cout << std::endl;
    }

    return 0;
}


#include<iostream>
#include<cstdio>
#include<vector>
#include<queue>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<map>
#include<set>
#include<string>
#include<cstring>
using namespace std;
#define max 1005
int n,k;
struct info
{
    int cost,no;
};
double cost=0;
vector< int > res[max];
vector< pair<int,int> > stool;
vector< pair<int,int> > pen;
int costlist[max];
bool comp(pair<int,int> a, pair<int,int> b)
{
    return a.first>b.first;
}
bool comp1(pair<int,int> a, pair<int,int> b)
{
    return a.first<b.first;
}
int main()
{
    int i,j,c,t;
    cin>>n>>k;
    for(i=1;i<=n;i++)
    {
        cin>>c>>t;
        if(t==1)
        {
            stool.push_back(make_pair(c,i));
        }
        else pen.push_back(make_pair(c,i));
        costlist[i]=c;
    }
    sort(stool.begin(),stool.end(),comp);
    sort(pen.begin(),pen.end(),comp1);
    if(stool.size()<=k)
    {
        int s = stool.size();
        for(i=0;i<s;i++)
        {
            res[i].push_back(stool[i].second);
            cost+=(double)stool[i].first*0.5;
        }
        int left = k-s;
        for(i=0;i<left;i++)
        {
            res[s+i].push_back(pen[i].second);
            cost+=pen[i].first;
        }
        s =pen.size();
        for(i=0;i<s-left;i++)
        {
            res[k-1].push_back(pen[i+left].second);
            cost+=pen[i+left].first;
        }
        if(stool.size()==k && pen.size())
        {
            if(stool[stool.size()-1].first>pen[0].first)
            {
                cost+=(stool[stool.size()-1].first*0.5 - pen[0].first*0.5);
            }
        }
    }
    else
    {
        for(i=0;i<k-1;i++)
        {
            res[i].push_back(stool[i].second);
            cost+=(double)stool[i].first*0.5;
        }

        if(pen.size()==0 || stool[stool.size()-1].first<pen[0].first)
        {
            int left = stool.size()-k+1;
            for(i=0;i<left-1;i++)
            {
                res[k-1].push_back(stool[i+k-1].second);
                cost+=stool[i+k-1].first;
            }
            res[k-1].push_back(stool[stool.size()-1].second);
            cost+=(double)stool[stool.size()-1].first*0.5;
            for(i=0;i<pen.size();i++)
            {
                res[k-1].push_back(pen[i].second);
                cost+=pen[i].first;
            }
        }
        else
        {
            int left = stool.size()-k+1;
            for(i=0;i<left;i++)
            {
                res[k-1].push_back(stool[i+k-1].second);
                cost+=stool[i+k-1].first;
            }
            res[k-1].push_back(pen[0].second);
            cost+=(double)pen[0].first*0.5;
            for(i=1;i<pen.size();i++)
            {
                res[k-1].push_back(pen[i].second);
                cost+=pen[i].first;
            }
        }

    }
    printf("%.1lf\n",cost);
    for(i=0;i<k;i++)
    {
        cout<<res[i].size();
        for(j=0;j<res[i].size();j++)
        {
            cout<<" "<<res[i][j];
        }
        cout<<endl;
    }

    return 0;
}


#include<iostream>
#include<cstdio>
#include<vector>
#include<queue>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<map>
#include<set>
#include<string>
#include<cstring>
using namespace std;
#define max 1005
int n,k;
struct info
{
    int cost,no;
};
double cost=0;
vector<int> res[max];
vector< pair<int,int> > stool;
vector< pair<int,int> > pen;
bool comp(pair<int,int> a, pair<int,int> b)
{
    return a.first>b.first;
}
int main()
{
    int i,j,c,t;
    cin>>n>>k;
    for(i=1;i<=n;i++)
    {
        cin>>c>>t;
        if(t==1)
        {
            stool.push_back(make_pair(c,i));
        }
        else pen.push_back(make_pair(c,i));
    }

    if(stool.size()<=k)
    {
        int s = stool.size();
        for(i=0;i<s;i++)
        {
            res[i].push_back(stool[i].second);
            cost+=(double)stool[i].first*0.5;
        }
        int left = k-s;
        for(i=0;i<left;i++)
        {
            res[s+i].push_back(pen[i].second);
            cost+=pen[i].first;
        }
        s =pen.size();
        for(i=0;i<s-left;i++)
        {
            res[k-1].push_back(pen[i+left].second);
            cost+=pen[i+left].first;
        }
    }
    else
    {
        sort(stool.begin(),stool.end(),comp);

        for(i=0;i<k-1;i++)
        {
            res[i].push_back(stool[i].second);
            cost+=(double)stool[i].first*0.5;
        }
        int left = stool.size()-k+1;
        for(i=0;i<left-1;i++)
        {
            res[k-1].push_back(stool[i+k-1].second);
            cost+=stool[i+k-1].first;
        }
        res[k-1].push_back(stool[stool.size()-1].second);
        cost+=(double)stool[stool.size()-1].first;
        for(i=0;i<pen.size();i++)
        {
            res[0].push_back(pen[i].second);
            cost+=pen[i].first;
        }
    }
    printf("%.1lf\n",cost);
    for(i=0;i<k;i++)
    {
        cout<<res[i].size();
        for(j=0;j<res[i].size();j++)
        {
            cout<<" "<<res[i][j];
        }
        cout<<endl;
    }

    return 0;
}


#include<iostream>
#include<cstdio>
#include<vector>
#include<queue>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<map>
#include<set>
#include<string>
#include<cstring>
using namespace std;
#define max 1005
int n,k;
struct info
{
    int cost,no;
};
double cost=0;
vector< int > res[max];
vector< pair<int,int> > stool;
vector< pair<int,int> > pen;
int costlist[max];
bool comp(pair<int,int> a, pair<int,int> b)
{
    return a.first>b.first;
}
bool comp1(pair<int,int> a, pair<int,int> b)
{
    return a.first<b.first;
}
int main()
{
    int i,j,c,t;
    cin>>n>>k;
    for(i=1;i<=n;i++)
    {
        cin>>c>>t;
        if(t==1)
        {
            stool.push_back(make_pair(c,i));
        }
        else pen.push_back(make_pair(c,i));
        costlist[i]=c;
    }
    //sort(stool.begin(),stool.end(),comp)
    if(stool.size()<=k)
    {
        int s = stool.size();
        for(i=0;i<s;i++)
        {
            res[i].push_back(stool[i].second);
            cost+=(double)stool[i].first*0.5;
        }
        int left = k-s;
        for(i=0;i<left;i++)
        {
            res[s+i].push_back(pen[i].second);
            cost+=pen[i].first;
        }
        s =pen.size();
        for(i=0;i<s-left;i++)
        {
            res[k-1].push_back(pen[i+left].second);
            cost+=pen[i+left].first;
        }
    }
    else
    {
        sort(stool.begin(),stool.end(),comp);
        sort(pen.begin(),pen.end(),comp1);
        for(i=0;i<k-1;i++)
        {
            res[i].push_back(stool[i].second);
            cost+=(double)stool[i].first*0.5;
        }

        if(pen.size()==0 || stool[stool.size()-1].first<pen[0].first)
        {
            int left = stool.size()-k+1;
            for(i=0;i<left-1;i++)
            {
                res[k-1].push_back(stool[i+k-1].second);
                cost+=stool[i+k-1].first;
            }
            res[k-1].push_back(stool[stool.size()-1].second);
            cost+=(double)stool[stool.size()-1].first*0.5;
            for(i=0;i<pen.size();i++)
            {
                res[k-1].push_back(pen[i].second);
                cost+=pen[i].first;
            }
        }
        else
        {
            int left = stool.size()-k+1;
            for(i=0;i<left;i++)
            {
                res[k-1].push_back(stool[i+k-1].second);
                cost+=stool[i+k-1].first;
            }
            res[k-1].push_back(pen[0].second);
            cost+=(double)pen[0].first*0.5;
            for(i=1;i<pen.size();i++)
            {
                res[k-1].push_back(pen[i].second);
                cost+=pen[i].first;
            }
        }

    }
    printf("%.1lf\n",cost);
    for(i=0;i<k;i++)
    {
        cout<<res[i].size();
        for(j=0;j<res[i].size();j++)
        {
            cout<<" "<<res[i][j];
        }
        cout<<endl;
    }

    return 0;
}


#include<iostream>
#include<cstdio>
#include<vector>
#include<queue>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<map>
#include<set>
#include<string>
#include<cstring>
using namespace std;
#define max 1005
int n,k;
struct info
{
    int cost,no;
};
double cost=0;
vector< int > res[max];
vector< pair<int,int> > stool;
vector< pair<int,int> > pen;
int costlist[max];
bool comp(pair<int,int> a, pair<int,int> b)
{
    return a.first>b.first;
}
bool comp1(pair<int,int> a, pair<int,int> b)
{
    return a.first<b.first;
}
int main()
{
    int i,j,c,t;
    cin>>n>>k;
    for(i=1;i<=n;i++)
    {
        cin>>c>>t;
        if(t==1)
        {
            stool.push_back(make_pair(c,i));
        }
        else pen.push_back(make_pair(c,i));
        costlist[i]=c;
    }
    sort(stool.begin(),stool.end(),comp);
    sort(pen.begin(),pen.end(),comp1);
    if(stool.size()<=k)
    {
        int s = stool.size();
        for(i=0;i<s;i++)
        {
            res[i].push_back(stool[i].second);
            cost+=(double)stool[i].first*0.5;
        }
        int left = k-s;
        for(i=0;i<left;i++)
        {
            res[s+i].push_back(pen[i].second);
            cost+=pen[i].first;
        }
        s =pen.size();
        for(i=0;i<s-left;i++)
        {
            res[k-1].push_back(pen[i+left].second);
            cost+=pen[i+left].first;
        }
        if(stool.size()==k)
        {
            if(stool[stool.size()-1].first>pen[0].first)
            {
                cost+=(stool[stool.size()-1].first*0.5 - pen[0].first*0.5);
            }
        }
    }
    else
    {
        for(i=0;i<k-1;i++)
        {
            res[i].push_back(stool[i].second);
            cost+=(double)stool[i].first*0.5;
        }

        if(pen.size()==0 || stool[stool.size()-1].first<pen[0].first)
        {
            int left = stool.size()-k+1;
            for(i=0;i<left-1;i++)
            {
                res[k-1].push_back(stool[i+k-1].second);
                cost+=stool[i+k-1].first;
            }
            res[k-1].push_back(stool[stool.size()-1].second);
            cost+=(double)stool[stool.size()-1].first*0.5;
            for(i=0;i<pen.size();i++)
            {
                res[k-1].push_back(pen[i].second);
                cost+=pen[i].first;
            }
        }
        else
        {
            int left = stool.size()-k+1;
            for(i=0;i<left;i++)
            {
                res[k-1].push_back(stool[i+k-1].second);
                cost+=stool[i+k-1].first;
            }
            res[k-1].push_back(pen[0].second);
            cost+=(double)pen[0].first*0.5;
            for(i=1;i<pen.size();i++)
            {
                res[k-1].push_back(pen[i].second);
                cost+=pen[i].first;
            }
        }

    }
    printf("%.1lf\n",cost);
    for(i=0;i<k;i++)
    {
        cout<<res[i].size();
        for(j=0;j<res[i].size();j++)
        {
            cout<<" "<<res[i][j];
        }
        cout<<endl;
    }

    return 0;
}


#include<iostream>
#include<cstdio>
#include<vector>
#include<queue>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<map>
#include<set>
#include<string>
#include<cstring>
using namespace std;
#define max 1005
int n,k;
struct info
{
    int cost,no;
};
double cost=0;
vector< int > res[max];
vector< pair<int,int> > stool;
vector< pair<int,int> > pen;
int costlist[max];
bool comp(pair<int,int> a, pair<int,int> b)
{
    return a.first>b.first;
}
bool comp1(pair<int,int> a, pair<int,int> b)
{
    return a.first<b.first;
}
int main()
{
    int i,j,c,t;
    cin>>n>>k;
    for(i=1;i<=n;i++)
    {
        cin>>c>>t;
        if(t==1)
        {
            stool.push_back(make_pair(c,i));
        }
        else pen.push_back(make_pair(c,i));
        costlist[i]=c;
    }
    //sort(stool.begin(),stool.end(),comp)
    if(stool.size()<=k)
    {
        int s = stool.size();
        for(i=0;i<s;i++)
        {
            res[i].push_back(stool[i].second);
            cost+=(double)stool[i].first*0.5;
        }
        int left = k-s;
        for(i=0;i<left;i++)
        {
            res[s+i].push_back(pen[i].second);
            cost+=pen[i].first;
        }
        s =pen.size();
        for(i=0;i<s-left;i++)
        {
            res[k-1].push_back(pen[i+left].second);
            cost+=pen[i+left].first;
        }
    }
    else
    {
        sort(stool.begin(),stool.end(),comp);
        sort(pen.begin(),pen.end(),comp1);
        for(i=0;i<k-1;i++)
        {
            res[i].push_back(stool[i].second);
            cost+=(double)stool[i].first*0.5;
        }
        if(stool[stool.size()-1].first<pen[0].first)
        {
            int left = stool.size()-k+1;
            for(i=0;i<left-1;i++)
            {
                res[k-1].push_back(stool[i+k-1].second);
                cost+=stool[i+k-1].first;
            }
            res[k-1].push_back(stool[stool.size()-1].second);
            cost+=(double)stool[stool.size()-1].first*0.5;
            for(i=0;i<pen.size();i++)
            {
                res[k-1].push_back(pen[i].second);
                cost+=pen[i].first;
            }
        }
        else
        {
            int left = stool.size()-k+1;
            for(i=0;i<left;i++)
            {
                res[k-1].push_back(stool[i+k-1].second);
                cost+=stool[i+k-1].first;
            }
            res[k-1].push_back(pen[0].second);
            cost+=(double)pen[0].first*0.5;
            for(i=1;i<pen.size();i++)
            {
                res[k-1].push_back(pen[i].second);
                cost+=pen[i].first;
            }
        }

    }
    printf("%.1lf\n",cost);
    for(i=0;i<k;i++)
    {
        cout<<res[i].size();
        for(j=0;j<res[i].size();j++)
        {
            cout<<" "<<res[i][j];
        }
        cout<<endl;
    }

    return 0;
}


#include<iostream>
#include<cstdio>
#include<vector>
#include<queue>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<map>
#include<set>
#include<string>
#include<cstring>
using namespace std;
#define max 1005
int n,k;
struct info
{
    int cost,no;
};
double cost=0;
vector< pair<int,int> > res[max];
vector< pair<int,int> > stool;
vector< pair<int,int> > pen;
int costlist[max];
bool comp(pair<int,int> a, pair<int,int> b)
{
    return a.first>b.first;
}
bool comp1(pair<int,int> a, pair<int,int> b)
{
    return a.first<b.first;
}
int main()
{
    int i,j,c,t;
    cin>>n>>k;
    for(i=1;i<=n;i++)
    {
        cin>>c>>t;
        if(t==1)
        {
            stool.push_back(make_pair(c,i));
        }
        else pen.push_back(make_pair(c,i));
        costlist[i]=c;
    }
    //sort(stool.begin(),stool.end(),comp)
    if(stool.size()<=k)
    {
        int s = stool.size();
        for(i=0;i<s;i++)
        {
            res[i].push_back(stool[i]);
            cost+=(double)stool[i].first*0.5;
        }
        int left = k-s;
        for(i=0;i<left;i++)
        {
            res[s+i].push_back(pen[i]);
            cost+=pen[i].first;
        }
        s =pen.size();
        for(i=0;i<s-left;i++)
        {
            res[k-1].push_back(pen[i+left]);
            cost+=pen[i+left].first;
        }
    }
    else
    {
        sort(stool.begin(),stool.end(),comp);
        sort(pen.begin(),pen.end(),comp1)
        for(i=0;i<k-1;i++)
        {
            res[i].push_back(stool[i].second);
            cost+=(double)stool[i].first*0.5;
        }
        if(stool[stool.size()-1].first<pen[0].first)
        {
            int left = stool.size()-k+1;
            for(i=0;i<left-1;i++)
            {
                res[k-1].push_back(stool[i+k-1].second);
                cost+=stool[i+k-1].first;
            }
            res[k-1].push_back(stool[stool.size()-1].second);
            cost+=(double)stool[stool.size()-1].first*0.5;
            for(i=0;i<pen.size();i++)
            {
                res[k-1].push_back(pen[i].second);
                cost+=pen[i].first;
            }
        }
        else
        {
            int left = stool.size()-k+1;
            for(i=0;i<left;i++)
            {
                res[k-1].push_back(stool[i+k-1].second);
                cost+=stool[i+k-1].first;
            }
            res[k-1].push_back(pen[0].second);
            cost+=(double)pen[0].first*0.5;
            for(i=1;i<pen.size();i++)
            {
                res[k-1].push_back(pen[i].second);
                cost+=pen[i].first;
            }
        }

    }
    printf("%.1lf\n",cost);
    for(i=0;i<k;i++)
    {
        cout<<res[i].size();
        for(j=0;j<res[i].size();j++)
        {
            cout<<" "<<res[i][j];
        }
        cout<<endl;
    }

    return 0;
}


#include<iostream>
#include<cstdio>
#include<vector>
#include<queue>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<map>
#include<set>
#include<string>
#include<cstring>
using namespace std;
#define max 1005
int n,k;
struct info
{
    int cost,no;
};
double cost=0;
vector<int> res[max];
vector< pair<int,int> > stool;
vector< pair<int,int> > pen;
bool comp(pair<int,int> a, pair<int,int> b)
{
    return a.first>b.first;
}
int main()
{
    int i,j,c,t;
    cin>>n>>k;
    for(i=1;i<=n;i++)
    {
        cin>>c>>t;
        if(t==1)
        {
            stool.push_back(make_pair(c,i));
        }
        else pen.push_back(make_pair(c,i));
    }

    if(stool.size()<=k)
    {
        int s = stool.size();
        for(i=0;i<s;i++)
        {
            res[i].push_back(stool[i].second);
            cost+=(double)stool[i].first*0.5;
        }
        int left = k-s;
        for(i=0;i<left;i++)
        {
            res[s+i].push_back(pen[i].second);
            cost+=pen[i].first;
        }
        s =pen.size();
        for(i=0;i<s-left;i++)
        {
            res[k-1].push_back(pen[i+left].second);
            cost+=pen[i+left].first;
        }
    }
    else
    {
        sort(stool.begin(),stool.end(),comp);

        for(i=0;i<k-1;i++)
        {
            res[i].push_back(stool[i].second);
            cost+=(double)stool[i].first*0.5;
        }
        int left = stool.size()-k+1;
        for(i=0;i<left-1;i++)
        {
            res[k-1].push_back(stool[i+k-1].second);
            cost+=stool[i+k-1].first;
        }
        res[k-1].push_back(stool[stool.size()-1].second);
        cost+=(double)stool[stool.size()-1].first*0.5;
        for(i=0;i<pen.size();i++)
        {
            res[0].push_back(pen[i].second);
            cost+=pen[i].first;
        }
    }
    printf("%.1lf\n",cost);
    for(i=0;i<k;i++)
    {
        cout<<res[i].size();
        for(j=0;j<res[i].size();j++)
        {
            cout<<" "<<res[i][j];
        }
        cout<<endl;
    }

    return 0;
}


#include <iostream>
#include <utility>
#include <algorithm>
#include <vector>
#include <iomanip>

using namespace std;

const int inf = 1000000000;

int n, k;
double ans;
vector < pair <int, int> > stool, pencil;
vector < pair <pair <int, int>, int> > cart[1010], item;

bool cmp(pair <int, int> u, pair <int, int> v) {
	if (u.first != v.first)
		return u.first > v.first;
	return u.second < v.second;
}

int main() {
	cin >> n >> k;
	for (int i = 1; i <= n; i++) {
		int c, t;
		scanf("%d %d", &c, &t);
		if (t == 1)
			stool.push_back(make_pair(c, i));
		else
			item.push_back(make_pair(make_pair(c, i), 2));
	}

	sort(stool.begin(), stool.end(), cmp);
	for (int i = 0; i < min(k, (int)stool.size()); i++) {
		cart[i].push_back(make_pair(stool[i], 1));
	}

	for (int i = min(k, (int)stool.size()); i < stool.size(); i++)
		item.push_back(make_pair(stool[i], 1));
	sort(item.begin(), item.end());

	for (int i = k - 1; i >= 0 && cart[i].size() == 0; i--) {
		cart[i].push_back(*item.rbegin());
		item.pop_back();
	}
	for (int i = item.size() - 1; i >= 0; i--)
		cart[k - 1].push_back(item[i]);
	for (int u = 0; u < k; u++) {
		double temp = inf;
		bool has_stool = false;
		for (int i = 0; i < cart[u].size(); i++) {
			if (cart[u][i].second == 1)
				has_stool = true;
			ans += cart[u][i].first.first;
			temp = min(temp, (double)cart[u][i].first.first);
		}
		if (has_stool) ans -= temp * 0.5;
	}
	cout << setprecision(1) << setiosflags(ios::fixed | ios::showpoint | ios::right) << ans << endl;
	for (int u = 0; u < k; u++) {
		cout << cart[u].size();
		for (int i = 0; i < cart[u].size(); i++)
			cout << ' ' << cart[u][i].first.second;
		cout << endl;
	}
}


#include <iostream>
#include <utility>
#include <algorithm>
#include <vector>
#include <iomanip>

using namespace std;

const int inf = 1000000000;

int n, k;
double ans;
vector < pair <int, int> > stool, pencil;
vector < pair <pair <int, int>, int> > cart[1010], item;

bool cmp(pair <int, int> u, pair <int, int> v) {
	if (u.first != v.first)
		return u.first > v.first;
	return u.second < v.second;
}

int main() {
	cin >> n >> k;
	for (int i = 1; i <= n; i++) {
		int c, t;
		scanf("%d %d", &c, &t);
		if (t == 1)
			stool.push_back(make_pair(c, i));
		else
			item.push_back(make_pair(make_pair(c, i), 2));
	}

	sort(stool.begin(), stool.end(), cmp);
	for (int i = 0; i < min(k, (int)stool.size()); i++) {
		cart[i].push_back(make_pair(stool[i], 1));
	}

	for (int i = min(k, (int)stool.size()); i < stool.size(); i++)
		item.push_back(make_pair(stool[i], 1));
	sort(item.begin(), item.end());

	for (int i = min(k, (int)item.size()) - 1; i >= 0 && cart[i].size() == 0; i--) {
		cart[i].push_back(*item.rbegin());
		item.pop_back();
	}
	for (int i = item.size() - 1; i >= 0; i--)
		cart[k - 1].push_back(item[i]);
	for (int u = 0; u < k; u++) {
		double temp = inf;
		bool has_stool = false;
		for (int i = 0; i < cart[u].size(); i++) {
			if (cart[u][i].second == 1)
				has_stool = true;
			ans += cart[u][i].first.first;
			temp = min(temp, (double)cart[u][i].first.first);
		}
		if (has_stool) ans -= temp * 0.5;
	}
	cout << setprecision(1) << setiosflags(ios::fixed | ios::showpoint | ios::right) << ans << endl;
	for (int u = 0; u < k; u++) {
		cout << cart[u].size();
		for (int i = 0; i < cart[u].size(); i++)
			cout << ' ' << cart[u][i].first.second;
		cout << endl;
	}
}


#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <algorithm>

using namespace std;

vector<int> vertex, vertex_;
vector<int> g[1100];
int c[1100];

bool cmp(int a, int b)
{
    return c[a] < c[b];
}

void DoIt(vector<int> & vertex, int i, long long & ans, int k = 1)
{
    int vb = vertex_.back();
    g[i].push_back(vb);
    ans += k * c[vb];
    vertex_.pop_back();
}

int main()
{
    int n, k;
    scanf("%d %d", &n, &k);
    for(int i = 0; i < n; i++)
    {
        int t;
        scanf("%d %d", &c[i], &t);
        if(t == 1)
        {
            vertex.push_back(i);
        }
        else
        {
            vertex_.push_back(i);
        }
    }
    sort(vertex.begin(), vertex.end(), cmp);
    sort(vertex_.begin(), vertex_.end(), cmp);
    int left = k;
    long long ans = 0;
    for(int i = 0; i < k - 1; i++)
    {
        if(!vertex.empty())
        {
            DoIt(vertex, i, ans);
        }
        else
        {
            DoIt(vertex_, i, ans, 2);
        }
    }
    for(int i = 0; i < vertex.size(); i++)
    {
        g[k - 1].push_back(vertex[i]);
    }
    for(int i = 0; i < vertex_.size(); i++)
    {
        g[k - 1].push_back(vertex_[i]);
    }
    sort(g[k - 1].begin(), g[k - 1].end(), cmp);
    for(int i = 0; i < g[k - 1].size(); i++)
    {
        ans += 2 * c[g[k - 1][i]];
    }
    if(!vertex.empty())
    {
        ans -= c[g[k - 1][0]];
    }
    printf("%I64d.%I64d\n", ans / 2, (ans % 2) * 5);
    for(int i = 0; i < k; i++)
    {
        printf("%d ", g[i].size());
        for(int j = 0; j < g[i].size(); j++)
        {
            printf("%d ", g[i][j] + 1);
        }
        printf("\n");
    }
    return 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <algorithm>

using namespace std;

vector<int> vertex, vertex_;
vector<int> g[1100];
int c[1100];

bool cmp(int a, int b)
{
    return c[a] < c[b];
}

void DoIt(vector<int> & vertex, int i, long long & ans, int k = 1)
{
    int vb = vertex.back();
    g[i].push_back(vb);
    ans += k * c[vb];
    vertex.pop_back();
}

int main()
{
    int n, k;
    scanf("%d %d", &n, &k);
    for(int i = 0; i < n; i++)
    {
        int t;
        scanf("%d %d", &c[i], &t);
        if(t == 1)
        {
            vertex.push_back(i);
        }
        else
        {
            vertex_.push_back(i);
        }
    }
    sort(vertex.begin(), vertex.end(), cmp);
    sort(vertex_.begin(), vertex_.end(), cmp);
    int left = k;
    long long ans = 0;
    for(int i = 0; i < k - 1; i++)
    {
        if(!vertex.empty())
        {
            DoIt(vertex, i, ans);
        }
        else
        {
            DoIt(vertex_, i, ans, 2);
        }
    }
    for(int i = 0; i < vertex.size(); i++)
    {
        g[k - 1].push_back(vertex[i]);
    }
    for(int i = 0; i < vertex_.size(); i++)
    {
        g[k - 1].push_back(vertex_[i]);
    }
    sort(g[k - 1].begin(), g[k - 1].end(), cmp);
    for(int i = 0; i < g[k - 1].size(); i++)
    {
        ans += 2 * c[g[k - 1][i]];
    }
    if(!vertex.empty())
    {
        ans -= c[g[k - 1][0]];
    }
    printf("%I64d.%I64d\n", ans / 2, (ans % 2) * 5);
    for(int i = 0; i < k; i++)
    {
        printf("%d ", g[i].size());
        for(int j = 0; j < g[i].size(); j++)
        {
            printf("%d ", g[i][j] + 1);
        }
        printf("\n");
    }
    return 0;
}


#include <iostream>
#include <fstream>
#include <cstdlib>
#include <algorithm>
#include <math.h>
#include <vector>
using namespace std;

#define ll long long

int main ()
{
	int n, k;
	cin >> n >> k;
	vector<vector<int> > ans(k);
	vector<pair<int, int> > chair, pencil;
	for(int i = 0; i < n; ++i)
	{
		int c, t;
		cin >> c >> t;
		if(t == 1)
			chair.push_back(make_pair(c, i));
		else
			pencil.push_back(make_pair(c, i));
	}
	sort(chair.begin(), chair.end());
	sort(pencil.begin(), pencil.end());
	if(k == 0)
	{
		ll res = 0;
		int mn = 2e9;
		for(int i = 0; i < chair.size(); ++i)
		{
			res += 2*chair[i].first;
			ans[0].push_back(chair[i].second);
			mn = min(chair[i].first, mn);
		}
		for(int i = 0; i < pencil.size(); ++i)
		{
			res += 2*pencil[i].first;
			ans[0].push_back(pencil[i].second);
			mn = min(pencil[i].first, mn);
		}
		if(chair.size() == 0)
			mn = 0;
		res -= mn;
		cout << res / 2 << '.' << (res & 1 ? 5 : 0) << endl << n << " ";
		for(int i = 0; i < n; ++i)
			cout << i+1 << endl;
		return 0;
	}
	if(chair.size() < k)
	{
		ll res = 0;
		reverse(pencil.begin(), pencil.end());
		for(int i = 0; i < chair.size(); ++i)
		{
			ans[i].push_back(chair[i].second);
			res += chair[i].first;
		}

		for(int i = chair.size(); i < k; ++i)
		{
			res += 2*pencil.back().first;
			ans[i].push_back(pencil.back().second);
			pencil.pop_back();
		}
		for(int i = 0; i < pencil.size(); ++i)
		{
			res += 2*pencil[i].first;
			ans.back().push_back(pencil[i].second);
		}
		cout << res / 2 << '.' << (res & 1 ? 5 : 0);
	}
	else
	{
		ll res = 0;
		for(int i = k-1; i >= 1; --i)
		{
			res += chair.back().first;
			ans[i].push_back(chair.back().second);
			chair.pop_back();
		}
		ll sum = 0;
		int mn = 2e9;
		for(int i = 0; i < chair.size(); ++i)
		{
			sum += chair[i].first;
			mn = min(mn, chair[i].first);
			ans[0].push_back(chair[i].second);
		}
		for(int i = 0; i < pencil.size(); ++i)
		{
			sum += pencil[i].first;
			mn = min(mn, pencil[i].first);
			ans[0].push_back(pencil[i].second);
		}
		ll div = abs(res - mn);
		res = (res - mn) + 2*sum;
		cout << res / 2 << '.' << (div & 1 ? 5 : 0);
	}
	cout << endl;
	for(int i = 0; i < k; ++i, cout << endl)
	{
		cout << ans[i].size() << " ";
		for(int j = 0; j < ans[i].size(); ++j)
			cout << ans[i][j] + 1 << " ";
	}

	return 0;
}


#include <iostream>
#include <fstream>
#include <cstdlib>
#include <algorithm>
#include <math.h>
#include <vector>
using namespace std;

#define ll long long

int main ()
{
	int n, k;
	cin >> n >> k;
	vector<vector<int> > ans(k);
	vector<pair<int, int> > chair, pencil;
	for(int i = 0; i < n; ++i)
	{
		int c, t;
		cin >> c >> t;
		if(t == 1)
			chair.push_back(make_pair(c, i));
		else
			pencil.push_back(make_pair(c, i));
	}
	sort(chair.begin(), chair.end());
	sort(pencil.begin(), pencil.end());
	if(k == 0)
	{
		ll res = 0;
		int mn = 2e9;
		for(int i = 0; i < chair.size(); ++i)
		{
			res += 2*chair[i].first;
			ans[0].push_back(chair[i].second);
			mn = min(chair[i].first, mn);
		}
		for(int i = 0; i < pencil.size(); ++i)
		{
			res += 2*pencil[i].first;
			ans[0].push_back(pencil[i].second);
			mn = min(pencil[i].first, mn);
		}
		if(chair.size() == 0)
			mn = 0;
		res -= mn;
		cout << res / 2 << '.' << (res & 1 ? 5 : 0) << endl << n << " ";
		for(int i = 0; i < n; ++i)
			cout << i+1 << endl;
		return 0;
	}
	if(chair.size() <= k)
	{
		ll res = 0;
		reverse(pencil.begin(), pencil.end());
		for(int i = 0; i < chair.size(); ++i)
		{
			ans[i].push_back(chair[i].second);
			res += chair[i].first;
		}

		for(int i = chair.size(); i < k; ++i)
		{
			res += 2*pencil.back().first;
			ans[i].push_back(pencil.back().second);
			pencil.pop_back();
		}
		for(int i = 0; i < pencil.size(); ++i)
		{
			res += 2*pencil[i].first;
			ans.back().push_back(pencil[i].second);
		}
		cout << res / 2 << '.' << (res & 1 ? 5 : 0);
	}
	else
	{
		ll res = 0;
		for(int i = k-1; i >= 1; --i)
		{
			res += chair.back().first;
			ans[i].push_back(chair.back().second);
			chair.pop_back();
		}
		ll sum = 0;
		int mn = 2e9;
		for(int i = 0; i < chair.size(); ++i)
		{
			sum += chair[i].first;
			mn = min(mn, chair[i].first);
			ans[0].push_back(chair[i].second);
		}
		for(int i = 0; i < pencil.size(); ++i)
		{
			sum += pencil[i].first;
			mn = min(mn, pencil[i].first);
			ans[0].push_back(pencil[i].second);
		}
		ll div = abs(res - mn);
		res = (res - mn) + 2*sum;
		cout << res / 2 << '.' << (div & 1 ? 5 : 0);
	}
	cout << endl;
	for(int i = 0; i < k; ++i, cout << endl)
	{
		cout << ans[i].size() << " ";
		for(int j = 0; j < ans[i].size(); ++j)
			cout << ans[i][j] + 1 << " ";
	}

	return 0;
}


#include <iostream>
#include <fstream>
#include <cstdlib>
#include <algorithm>
#include <math.h>
#include <vector>
using namespace std;

#define ll long long

int main ()
{
	int n, k;
	cin >> n >> k;
	vector<vector<int> > ans(k);
	vector<pair<int, int> > chair, pencil;
	for(int i = 0; i < n; ++i)
	{
		int c, t;
		cin >> c >> t;
		if(t == 1)
			chair.push_back(make_pair(c, i));
		else
			pencil.push_back(make_pair(c, i));
	}
	sort(chair.begin(), chair.end());
	sort(pencil.begin(), pencil.end());

	if(chair.size() <= k)
	{
		ll res = 0;
		reverse(pencil.begin(), pencil.end());
		for(int i = 0; i < chair.size(); ++i)
		{
			ans[i].push_back(chair[i].second);
			res += chair[i].first;
		}

		for(int i = chair.size(); i < k; ++i)
		{
			res += 2*pencil.back().first;
			ans[i].push_back(pencil.back().second);
			pencil.pop_back();
		}
		for(int i = 0; i < pencil.size(); ++i)
		{
			res += 2*pencil[i].first;
			ans.back().push_back(pencil[i].second);
		}
		cout << res / 2 << '.' << (res & 1 ? 5 : 0);
	}
	else
	{
		ll res = 0;
		for(int i = k-1; i >= 1; --i)
		{
			res += chair.back().first;
			ans[i].push_back(chair.back().second);
			chair.pop_back();
		}
		ll sum = 0;
		int mn = 2e9;
		for(int i = 0; i < chair.size(); ++i)
		{
			sum += chair[i].first;
			mn = min(mn, chair[i].first);
			ans[0].push_back(chair[i].second);
		}
		for(int i = 0; i < pencil.size(); ++i)
		{
			sum += pencil[i].first;
			mn = min(mn, pencil[i].first);
			ans[0].push_back(pencil[i].second);
		}
		ll div = abs(res - mn);
		res = (res - mn) / 2 + sum;
		cout << res << '.' << (div & 1 ? 5 : 0);
	}
	cout << endl;
	for(int i = 0; i < k; ++i, cout << endl)
	{
		cout << ans[i].size() << " ";
		for(int j = 0; j < ans[i].size(); ++j)
			cout << ans[i][j] + 1 << " ";
	}

	return 0;
}


#include <iostream>
#include <fstream>
#include <cstdlib>
#include <algorithm>
#include <math.h>
#include <vector>
using namespace std;

#define ll long long

int main ()
{
	int n, k;
	cin >> n >> k;
	vector<vector<int> > ans(k);
	vector<pair<int, int> > chair, pencil;
	for(int i = 0; i < n; ++i)
	{
		int c, t;
		cin >> c >> t;
		if(t == 1)
			chair.push_back(make_pair(c, i));
		else
			pencil.push_back(make_pair(c, i));
	}
	sort(chair.begin(), chair.end());
	sort(pencil.begin(), pencil.end());
	if(k == 0)
	{
		ll res = 0;
		int mn = 2e9;
		for(int i = 0; i < chair.size(); ++i)
		{
			res += 2*chair[i].first;
			ans[0].push_back(chair[i].second);
			mn = min(chair[i].first, mn);
		}
		for(int i = 0; i < pencil.size(); ++i)
		{
			res += 2*pencil[i].first;
			ans[0].push_back(pencil[i].second);
			mn = min(pencil[i].first, mn);
		}
		if(chair.size() == 0)
			mn = 0;
		res -= mn;
		cout << res / 2 << '.' << (res & 1 ? 5 : 0) << endl << n << " ";
		for(int i = 0; i < n; ++i)
			cout << i+1 << endl;
		return 0;
	}
	if(chair.size() < k)
	{
		ll res = 0;
		reverse(pencil.begin(), pencil.end());
		for(int i = 0; i < chair.size(); ++i)
		{
			ans[i].push_back(chair[i].second);
			res += chair[i].first;
		}

		for(int i = chair.size(); i < k; ++i)
		{
			res += 2*pencil.back().first;
			ans[i].push_back(pencil.back().second);
			pencil.pop_back();
		}
		for(int i = 0; i < pencil.size(); ++i)
		{
			res += 2*pencil[i].first;
			ans[0].push_back(pencil[i].second);
		}
		cout << res / 2 << '.' << (res & 1 ? 5 : 0);
	}
	else
	{
		ll res = 0;
		for(int i = k-1; i >= 1; --i)
		{
			res += chair.back().first;
			ans[i].push_back(chair.back().second);
			chair.pop_back();
		}
		ll sum = 0;
		int mn = 2e9;
		for(int i = 0; i < chair.size(); ++i)
		{
			sum += chair[i].first;
			mn = min(mn, chair[i].first);
			ans[0].push_back(chair[i].second);
		}
		for(int i = 0; i < pencil.size(); ++i)
		{
			sum += pencil[i].first;
			mn = min(mn, pencil[i].first);
			ans[0].push_back(pencil[i].second);
		}
		ll div = abs(res - mn);
		res = (res - mn) + 2*sum;
		cout << res / 2 << '.' << (div & 1 ? 5 : 0);
	}
	cout << endl;
	for(int i = 0; i < k; ++i, cout << endl)
	{
		cout << ans[i].size() << " ";
		for(int j = 0; j < ans[i].size(); ++j)
			cout << ans[i][j] + 1 << " ";
	}

	return 0;
}


#include <iostream>
#include <algorithm>
#include <string>
#include <cstdio>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <cmath>

using namespace std;

#define all(a) a.begin(), a.end()
#define pb push_back
#define mp make_pair

#define li long long
#define ld long double

const int inf = 1000000000;
const ld eps = 1e-9;
const ld pi = 3.1415926535897932384626433832795;

vector<int>was[1001];
vector<int>anss[1001];
int used[1001];
int main()
{
    //freopen("input.txt", "rt", stdin);
    //freopen("output.txt", "wt", stdout);

    int n,k;
    cin>>n>>k;
    li tek=0LL;

    vector<pair<int,int>>tab;
    vector<pair<int,int>>kar;
    for(int i=1;i<=n;i++)
    {
        int a,b;
        cin>>a>>b;
        if(b==1)
            tab.pb(mp(a,i));
        else
            kar.pb(mp(a,i));
        tek+=(li)a;
    }
    sort(all(tab));
    reverse(all(tab));

    int kolt=tab.size();
    int kolk=kar.size();
    ld ans=0.0;
    for(int i=0;i<k;i++)
    {
        if(i==k-1)
        {
            if(i<=kolt-1)
                used[i]=1;
            for(int j=i;j<kolt;j++)
            {
                anss[i].pb(tab[j].second);
                was[i].pb(tab[j].first);
            }
            continue;
        }
        if(i>kolt-1)
            continue;
        was[i].pb(tab[i].first);
        anss[i].pb(tab[i].second);
        used[i]=1;
    }
    int uk=0;
    if(k<=kolt)
    {
        for(int i=0;i<kolk;i++)
        {
            was[k-1].pb(kar[i].first);
            anss[k-1].pb(kar[i].second);
        }

    }
    else
    {
        for(int i=kolt;i<k;i++)
        {
            if(i==k-1)
            {
                for(int j=uk;j<kolk;j++)
                {
                    was[i].pb(kar[j].first);
                    anss[i].pb(kar[j].second);
                }
                continue;
            }
            was[i].pb(kar[uk].first);
            anss[i].pb(kar[uk].second);
            uk++;
        }

    }

    for(int i=0;i<k;i++)
    {
        sort(all(was[i]));

    }
    for(int i=0;i<k;i++)
        if(used[i])
            ans+=was[i][0]/2.0;
    ld r=(ld)tek-ans;
    cout.precision(1);
    cout<<fixed<<r<<endl;
    for(int i=0;i<k;i++)
    {
        cout<<anss[i].size()<<' ';
        for(int j=0;j<anss[i].size();j++)
            cout<<anss[i][j]<<' ';
        cout<<endl;
    }

    return 0;
}


#include <iostream>
#include <algorithm>
#include <string>
#include <cstdio>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <cmath>

using namespace std;

#define all(a) a.begin(), a.end()
#define pb push_back
#define mp make_pair

#define li long long
#define ld long double

const int inf = 1000000000;
const ld eps = 1e-9;
const ld pi = 3.1415926535897932384626433832795;

vector<int>was[1001];
vector<int>anss[1001];
int used[1001];
int main()
{
 //   freopen("input.txt", "rt", stdin);
    //freopen("output.txt", "wt", stdout);

    int n,k;
    cin>>n>>k;
    li tek=0LL;

    vector<pair<int,int>>tab;
    vector<pair<int,int>>kar;
    for(int i=1;i<=n;i++)
    {
        int a,b;
        cin>>a>>b;
        if(b==1)
            tab.pb(mp(a,i));
        else
            kar.pb(mp(a,i));
        tek+=(li)a;
    }
    sort(all(tab));
    sort(all(kar));
    reverse(all(tab));
    reverse(all(kar));
    int kolt=tab.size();
    int kolk=kar.size();
    ld ans=0.0;
    for(int i=0;i<k;i++)
    {
        if(i==k-1)
        {
            if(i<=kolt-1)
                used[i]=1;
            for(int j=i;j<kolt;j++)
            {
                anss[i].pb(tab[j].second);
                was[i].pb(tab[j].first);
            }
            continue;
        }
        if(i>kolt-1)
            continue;
        was[i].pb(tab[i].first);
        anss[i].pb(tab[i].second);
        used[i]=1;
    }
    int uk=0;
    if(k<=kolt)
    {
        for(int i=0;i<kolk;i++)
        {
            was[k-1].pb(kar[i].first);
            anss[i].pb(kar[i].second);
        }
    }
    else
    {
        for(int i=kolt;i<k;i++)
        {
            if(i==k-1)
            {
                for(int j=uk;j<kolk;j++)
                {
                    was[i].pb(kar[j].first);
                    anss[i].pb(kar[j].second);
                }
                continue;
            }
            was[i].pb(kar[uk].first);
            anss[i].pb(kar[uk].second);
            uk++;
        }

    }

    for(int i=0;i<k;i++)
    {
        sort(all(was[i]));

    }
    for(int i=0;i<k;i++)
        if(used[i])
            ans+=was[i][0]/2.0;
    ld r=(ld)tek-ans;
    cout.precision(1);
    cout<<fixed<<r<<endl;
    for(int i=0;i<k;i++)
    {
        cout<<anss[i].size()<<' ';
        for(int j=0;j<anss[i].size();j++)
            cout<<anss[i][j]<<' ';
        cout<<endl;
    }

    return 0;
}


#include <iostream>
#include <algorithm>
#include <string>
#include <cstdio>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <cmath>

using namespace std;

#define all(a) a.begin(), a.end()
#define pb push_back
#define mp make_pair

#define li long long
#define ld long double

const int inf = 1000000000;
const ld eps = 1e-9;
const ld pi = 3.1415926535897932384626433832795;

vector<int>was[1001];
vector<int>anss[1001];
int used[1001];
int main()
{
   // freopen("input.txt", "rt", stdin);
    //freopen("output.txt", "wt", stdout);

    int n,k;
    cin>>n>>k;
    li tek=0LL;

    vector<pair<int,int>>tab;
    vector<pair<int,int>>kar;
    for(int i=1;i<=n;i++)
    {
        int a,b;
        cin>>a>>b;
        if(b==1)
        {
            tab.pb(mp(a,i));
        }
        else
            kar.pb(mp(a,i));
        tek+=(li)a;
    }
    sort(all(tab));
    sort(all(kar));
    reverse(all(tab));
    reverse(all(kar));
    int kolt=tab.size();
    int kolk=kar.size();
    ld ans=0.0;
    int uk1=0;
    int uk2=0;
    for(int i=0;i<k;i++)
    {
        if(i==k-1)
        {
            if(i<=kolt-1)
                used[i]=1;
            for(int j=i;j<kolt;j++)
            {
                anss[i].pb(tab[i].second);
                was[i].pb(tab[i].first);
            }
            continue;
        }
        if(i>kolt-1)
            continue;
        was[i].pb(tab[i].first);
        anss[i].pb(tab[i].second);
        used[i]=1;
    }
    int uk=0;
    if(k<=kolt)
    {
        for(int i=0;i<kolk;i++)
        {
            was[k-1].pb(kar[i].first);
            anss[i].pb(kar[i].second);
        }
    }
    else
    {
        for(int i=kolt;i<k;i++)
        {
            if(i==k-1)
            {
                for(int j=uk;j<kolk;j++)
                {
                    was[i].pb(kar[j].first);
                    anss[i].pb(kar[j].second);
                }
                continue;
            }
            was[i].pb(kar[uk].first);
            anss[i].pb(kar[uk].second);
            uk++;
        }

    }

    for(int i=0;i<k;i++)
    {
        sort(all(was[i]));

    }
    for(int i=0;i<k;i++)
        if(used[i])
            ans+=was[i][0]/2.0;
    ld r=(ld)tek-ans;
    cout.precision(1);
    cout<<fixed<<r<<endl;
    for(int i=0;i<k;i++)
    {
        cout<<anss[i].size()<<' ';
        for(int j=0;j<anss[i].size();j++)
            cout<<anss[i][j]<<' ';
        cout<<endl;
    }

    return 0;
}


#include <iostream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <algorithm>
#include <ctime>
#include <queue>
#include <cmath>
using namespace std;
typedef unsigned long long u64;
typedef long long i64;
typedef unsigned long long u32;
typedef long long i32;
const double EPS = 1e-9;

class item
{
public:
	item(int tt = 0, int cc = 0, int ii = 0): t(tt), c(cc), i(ii){}
	int t, c, i;
};

bool operator<(const item &a, const item &b)
{
	if(a.t != b.t) return a.t < b.t;

	return a.c > b.c;
}

int main()
{
	int n, k;
	cin >> n >> k;

	vector<item> v;

	int c, t;
	for(int i = 0; i < n; i++)
	{
		cin >> c >> t;
		v.push_back(item(t, c, i));
	}

	sort(v.begin(), v.end());

	vector<vector<int> > res(k);
	double sum = 0.0;
	for(int i = 0; i < k-1; i++)
	{
		res[i].push_back(v[i].i);
		if(v[i].t == 1)
			sum += double(v[i].c) / 2.0;
		else
			sum += v[i].c;
	}

	int mn = 1e20;
	bool ist = false;
	for(int i = k-1; i < v.size(); i++)
	{
		if(v[i].t == 1)
			ist = true;
		mn = min(mn, v[i].c);
		sum += v[i].c;

		res[k-1].push_back(v[i].i);
	}

	if(ist)
		sum -= mn / 2.0;

	printf("%0.1lf\n", sum);
	for(int i = 0; i < res.size(); i++)
	{
		cout << res[i].size();
		for(int j = 0; j < res[i].size(); j++)
			cout << " " << res[i][j]+1;
		cout << endl;
	}

	return 0;
}


#include <iostream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <algorithm>
#include <ctime>
#include <queue>
#include <cmath>
using namespace std;
typedef unsigned long long u64;
typedef long long i64;
typedef unsigned int u32;
typedef int i32;
const double EPS = 1e-9;

class good
{
public:
	good(int _type = 0, int _c = 0, int _id = 0): type(_type), c(_c), id(_id) {}
	int type, c, id;
};

bool operator<(const good &a, const good &b)
{
	return a.c < b.c;
}

int main()
{
	int tv, k;
	cin >> tv >> k;

	vector<good> tb, kr;
	vector<int> type(tv), c(tv);

	for(int i = 0; i < tv; i++)
	{
		cin >> c[i] >> type[i];
		if(type[i] == 1)
			tb.push_back(good(type[i], c[i], i+1));
		else
			kr.push_back(good(type[i], c[i], i+1));

	}

	vector<pair<int, pair<int, int> > > v;
	for(int i = 0; i < tb.size(); i++)
		for(int j = 0; j < kr.size(); j++)
			v.push_back(make_pair(min(tb[i].c, kr[j].c), make_pair(i, j)));

	for(int i = 0; i < tb.size(); i++)
		v.push_back(make_pair(tb[i].c, make_pair(i, -1)));

	for(int j = 0; j < kr.size(); j++)
		v.push_back(make_pair(0, make_pair(-1, j)));

	sort(v.rbegin(), v.rend());

	vector<int> tbused(tb.size());
	vector<int> krused(kr.size());

	vector<pair<int, int> > res;

	for(int i = 0; i < v.size(); i++)
	{
		if((v[i].second.first == -1 || !tbused[v[i].second.first]) && (v[i].second.second == -1 || !krused[v[i].second.second]))
		{
			res.push_back(v[i].second);
			if(v[i].second.first  != -1) tbused[v[i].second.first]  = 1;
			if(v[i].second.second != -1) krused[v[i].second.second] = 1;
		}
	}

	vector<vector<int> > ret(k);
	if(k < res.size())
	{
		for(int i = 0; i < k-1; i++)
		{
			if(res[i].first != -1)  ret[i].push_back(tb[res[i].first].id);
			if(res[i].second != -1) ret[i].push_back(kr[res[i].second].id);
		}

		for(int i = k-1; i < res.size(); i++)
		{
			if(res[i].first != -1)  ret[k-1].push_back(tb[res[i].first].id);
			if(res[i].second != -1) ret[k-1].push_back(kr[res[i].second].id);
		}
	}
	else
	{
		int left = k - res.size();
		for(int i = 0; i < res.size(); i++)
		{
			if(res[i].first != -1)  ret[i].push_back(tb[res[i].first].id);
			if(res[i].second != -1) ret[i].push_back(kr[res[i].second].id);
		}
		for(int i = 0; i < left; i++)
		{
			ret[res.size()+i].push_back(ret[res.size()-1-i].back());
			ret[res.size()-1-i].pop_back();
		}
	}

	double all = 0.0;
	for(int i = 0; i < ret.size(); i++)
	{
		bool ist = false;
		int mn = c[ret[i][0]-1];
		for(int j = 0; j < ret[i].size(); j++)
		{
			all += c[ret[i][j]-1];
			mn = min(mn, c[ret[i][j]-1]);
			if(type[ret[i][j]-1] == 1)
				ist = true;
		}

		if(ist) all -= double(mn) / 2.0;
	}

	printf("%0.1lf\n", all);

	for(int i = 0; i < ret.size(); i++)
	{
		cout << ret[i].size();
		for(int j = 0; j < ret[i].size(); j++)
			cout << " " << ret[i][j];
		cout << endl;
	}

	return 0;
}


#include <iostream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <algorithm>
#include <ctime>
#include <queue>
#include <cmath>
using namespace std;
typedef unsigned long long u64;
typedef long long i64;
typedef unsigned long long u32;
typedef long long i32;
const double EPS = 1e-9;

class good
{
public:
	good(long long _type = 0, long long _c = 0, long long _id = 0): type(_type), c(_c), id(_id) {}
	long long type, c, id;
};

bool operator<(const good &a, const good &b)
{
	return a.c < b.c;
}

int main()
{
	long long tv, k;
	cin >> tv >> k;

	vector<good> tb, kr;
	vector<long long> type(tv), c(tv);

	for(long long i = 0; i < tv; i++)
	{
		cin >> c[i] >> type[i];
		if(type[i] == 1)
			tb.push_back(good(type[i], c[i], i+1));
		else
			kr.push_back(good(type[i], c[i], i+1));

	}

	vector<pair<long long, pair<long long, long long> > > v;
	for(long long i = 0; i < tb.size(); i++)
		for(long long j = 0; j < kr.size(); j++)
			v.push_back(make_pair(min(tb[i].c, kr[j].c), make_pair(i, j)));

	for(long long i = 0; i < tb.size(); i++)
		v.push_back(make_pair(tb[i].c, make_pair(i, -1)));

	for(long long j = 0; j < kr.size(); j++)
		v.push_back(make_pair(0, make_pair(-1, j)));

	sort(v.rbegin(), v.rend());

	vector<long long> tbused(tb.size());
	vector<long long> krused(kr.size());

	vector<pair<long long, long long> > res;

	for(long long i = 0; i < v.size(); i++)
	{
		if((v[i].second.first == -1 || !tbused[v[i].second.first]) && (v[i].second.second == -1 || !krused[v[i].second.second]))
		{
			res.push_back(v[i].second);
			if(v[i].second.first  != -1) tbused[v[i].second.first]  = 1;
			if(v[i].second.second != -1) krused[v[i].second.second] = 1;
		}
	}

	vector<vector<long long> > ret(k);
	if(k < res.size())
	{
		for(long long i = 0; i < k-1; i++)
		{
			if(res[i].first != -1)  ret[i].push_back(tb[res[i].first].id);
			if(res[i].second != -1) ret[i].push_back(kr[res[i].second].id);
		}

		for(long long i = k-1; i < res.size(); i++)
		{
			if(res[i].first != -1)  ret[k-1].push_back(tb[res[i].first].id);
			if(res[i].second != -1) ret[k-1].push_back(kr[res[i].second].id);
		}
	}
	else
	{
		long long left = k - res.size();
		for(long long i = 0; i < res.size(); i++)
		{
			if(res[i].first != -1)  ret[i].push_back(tb[res[i].first].id);
			if(res[i].second != -1) ret[i].push_back(kr[res[i].second].id);
		}
		for(long long i = 0; i < left; i++)
		{
			ret[res.size()+i].push_back(ret[res.size()-1-i].back());
			ret[res.size()-1-i].pop_back();
		}
	}

	double all = 0.0;
	for(long long i = 0; i < ret.size(); i++)
	{
		bool ist = false;
		long long mn = c[ret[i][0]-1];
		for(long long j = 0; j < ret[i].size(); j++)
		{
			all += c[ret[i][j]-1];
			mn = min(mn, c[ret[i][j]-1]);
			if(type[ret[i][j]-1] == 1)
				ist = true;
		}

		if(ist) all -= double(mn) / 2.0;
	}

	printf("%0.1lf\n", all);

	for(long long i = 0; i < ret.size(); i++)
	{
		cout << ret[i].size();
		for(long long j = 0; j < ret[i].size(); j++)
			cout << " " << ret[i][j];
		cout << endl;
	}

	return 0;
}


#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <cmath>
#include <algorithm>
using namespace std;

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

int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
#endif

	int n,k;
	cin>>n>>k;
	pair<int,pair<int,bool>> a[1002];
	char c;
	for(int i=0;i<n;i++)
	{
		cin>>a[i].first>>c;
		a[i].second.second = (c=='2');
		a[i].second.first = i+1;
	}
	sort(a,a+n,comp);
	int now = 0;
	vector< vector<int> > res;
	int mint;
	bool type = false;
	long double sum = 0;
	for(int i=0;i<n;i++)
	{
		if(now!=k)
		{
			vector<int> t;
			t.push_back(i);
			res.push_back(t);
			now++;
			if(now==k)
			{
				mint = a[i].first;
				if(!a[i].second.second)
					type = true;
				if(type)
					sum += (double)a[i].first/2;
				else
					sum += a[i].first;
			}
			else
			{
				if(!a[i].second.second)
					sum += (double)a[i].first/2;
				else
					sum += a[i].first;
			}
		}
		else
		{
			{
				res[(int)res.size()-1].push_back(i);
				if(a[i].first<mint&&type)
				{
					sum -= (double)mint/2;
					mint = a[i].first;
					sum += (double)mint/2;
				}
				else
				{
					sum += a[i].first;
				}
			}
		}
	}
	printf("%.1lf\n",sum);
	for(int i=0;i<(int)res.size();i++)
	{
		cout<<(int)res[i].size()<<' ';
		for(int j=0;j<res[i].size();j++)
		{
			cout<<a[res[i][j]].second.first<<' ';
		}
		cout<<endl;
	}

    return 0;
}


#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <cmath>
#include <algorithm>
using namespace std;

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

int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
#endif

	int n,k;
	cin>>n>>k;
	pair<int,pair<int,bool>> a[1002];
	char c;
	for(int i=0;i<n;i++)
	{
		cin>>a[i].first>>c;
		a[i].second.second = (c=='2');
		a[i].second.first = i+1;
	}
	sort(a,a+n,comp);
	int now = 0;
	vector< vector<int> > res;
	int mint;
	bool type = false;
	long double sum = 0;
	for(int i=0;i<n;i++)
	{
		if(now!=k)
		{
			vector<int> t;
			t.push_back(i);
			res.push_back(t);
			now++;
			if(!a[i].second.second)
				sum += (double)a[i].first/2;
			else
				sum += a[i].first;
		}
		else
		{
			if(res.back().size()==0)
			{
				vector<int> t;
				t.push_back(i);
				res.push_back(t);
				mint = a[i].first;
				if(!a[i].second.second)
					type = true;
				if(type)
					sum += (double)a[i].first/2;
				else
					sum += a[i].first;
			}
			else
			{
				res[(int)res.size()-1].push_back(i);
				if(a[i].first<mint&&type)
				{
					sum -= (double)mint/2;
					mint = a[i].first;
					sum += (double)mint/2;
				}
				else
				{
					sum += a[i].first;
				}
			}
		}
	}
	printf("%.1lf\n",sum);
	for(int i=0;i<(int)res.size();i++)
	{
		cout<<(int)res[i].size()<<' ';
		for(int j=0;j<res[i].size();j++)
		{
			cout<<a[res[i][j]].second.first<<' ';
		}
		cout<<endl;
	}

    return 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <algorithm>
#include <stdio.h>

using namespace std;

struct item
{
    int p;
    int n;
};

bool comp1(item a, item b)
{
    return a.p > b.p;
}

bool comp2(item a, item b)
{
    return a.p < b.p;
}

int n,m,i,j,k,t,c;
item tab[1009],kar[1009];
int tc=0,kc=0;

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

    scanf("%d%d",&n,&k);
    for (i=0;i<n;i++)
    {
        scanf("%d%d",&c,&t);
        if (t==1)
        {
            tab[tc].n = i + 1;
            tab[tc].p = c;
            tc++;
        }
        else
        {
            kar[kc].n = i + 1;
            kar[kc].p = c;
            kc++;
        }
    }
    sort(tab,tab+tc,comp1);
    sort(kar,kar+kc,comp2);
    long double res = 0;
    i = 0;
    int c = 0;
    while (c<k-1 && i<tc)
    {
        res += (long double)tab[i].p/2.0;
        i++;
        c++;
    }
    int t1 = i;

    i = 0;
    while (c<k-1 && i<kc)
    {
        res += (long double)kar[i].p;
        i++;
        c++;
    }
    int t2 = i;
    bool bonus = false;
    int mi = 1000000009;
    for (i=t1;i<tc;i++)
    {
        res += tab[i].p;
        bonus = true;
        if (mi>tab[i].p)
            mi = tab[i].p;
    }
    for (i=t2;i<kc;i++)
    {
        res += kar[i].p;
        if (mi>kar[i].p)
            mi = kar[i].p;
    }
    if (bonus)
        res -= (long double)mi/2.0;
    //cout<<res<<endl;
    printf("%.1f\n",res);

    // ------------------------------------------------------------------

    c = 0;
    i = 0;
    while (c<k-1 && i<tc)
    {
        //res += (long double)tab[i].p/2.0;
        cout<<1<<" "<<tab[i].n<<endl;
        i++;
        c++;
    }
    t1 = i;

    i = 0;
    while (c<k-1 && i<kc)
    {
        //res += (long double)kar[i].p/2.0;
        cout<<1<<" "<<kar[i].n<<endl;
        i++;
        c++;
    }
    t2 = i;
    cout<<n-t1-t2<<" ";
    for (i=t1;i<tc;i++)
        cout<<tab[i].n<<" ";
        //res += tab[i].p;
    for (i=t2;i<kc;i++)
        cout<<kar[i].n<<" ";
        //res += kar[i].p;

    return 0;
}


#include <iostream>
#include <stdio.h>
#include <math.h>

using namespace std;

int main()
{
int n,k;
int i,j;

int a[1001];
int b[1001];
int c[1001];
int mm[1001];
int cnt;
double sum,max,s1,s2,min;
int q,dd;

cin >> n >> k;

cnt=0;
sum=0;
for (i=0;i<n;i++)
    {
        cin >> a[i] >> b[i];
        if (b[i]==1) cnt++;
        sum+=a[i];
    }

//

for (i=0;i<n;i++)
    {
        c[i]=-1;
        mm[i]=0;
}

dd=cnt;
if (cnt>k) dd=k;
s1=0;

max=-1;
for (i=0;i<dd;i++)
{
    max=0;
    q=-1;
    for (j=0;j<n;j++)
    {
        if (mm[j]!=0) continue;
        if (b[j]!=1) continue;
        if (a[j]>max)
        {
            q=j;
            max=a[j];
        }
    }
    mm[q]=1;
    c[i]=q;
    s1=s1+max;
}

if (dd==k)
{
    mm[q]=0;
    s1=s1-max;

    min=1500000000;
    for (i=0;i<n;i++)
    {
        if (mm[i]!=0) continue;
        if (a[i]<min) min = a[i];
    }

    s1=s1+min;
    dd--;
}
s2=sum-s1/2;
s1=floor(s2);
cout.precision(2);
cout <<s2 ;

if (s1==s2) cout<<'.'<<'0'<< endl;
else cout << endl;

for (i=0;i<dd;i++)
{
    cout << 1 <<' '<<c[i]+1<<endl;
}
//
//put in
for (i=dd;i<k-1;i++)
{
    cout << 1 <<' ';
    for (j=0;j<n;j++)
    {
        if (mm[j]!=0) continue;
        q=j;
        cout << q+1 <<endl;
        mm[q]=1;
        break;

    }

}

cnt=0;

for (i=0;i<n;i++) if (mm[i]==0) cnt++;
cout << cnt <<' ';
for (i=0;i<n;i++) if (mm[i]==0) cout << i+1 <<' ';
//cin >> i;

    return 0;
}


#include <iostream>
#include <stdio.h>

using namespace std;

int main()
{
int n,k;
int i,j;

int a[1001];
int b[1001];
int c[1001];
int mm[1001];
int cnt;
double sum,max,s1,s2,min;
int q,dd;

cin >> n >> k;

cnt=0;
sum=0;
for (i=0;i<n;i++)
    {
        cin >> a[i] >> b[i];
        if (b[i]==1) cnt++;
        sum+=a[i];
    }

//

for (i=0;i<n;i++)
    {
        c[i]=-1;
        mm[i]=0;
}

dd=cnt;
if (cnt>k) dd=k;
s1=0;

max=-1;
for (i=0;i<dd;i++)
{
    max=0;
    q=-1;
    for (j=0;j<n;j++)
    {
        if (mm[j]!=0) continue;
        if (b[j]!=1) continue;
        if (a[j]>max)
        {
            q=j;
            max=a[j];
        }
    }
    mm[q]=1;
    c[i]=q;
    s1=s1+max;
}

if (dd==k)
{
    mm[q]=0;
    s1=s1-max;

    min=1500000000;
    for (i=0;i<n;i++)
    {
        if (mm[i]!=0) continue;
        if (a[i]<min) min = a[i];
    }

    s1=s1+min;
    dd--;
}
s2=sum-s1/2;
s1=floor(s2);
cout.precision(2);
cout <<s2 ;

if (s1==s2) cout<<'.'<<'0'<< endl;
else cout << endl;

for (i=0;i<dd;i++)
{
    cout << 1 <<' '<<c[i]+1<<endl;
}
//
//put in
for (i=dd;i<k-1;i++)
{
    cout << 1 <<' ';
    for (j=0;j<n;j++)
    {
        if (mm[j]!=0) continue;
        q=j;
        cout << q+1 <<endl;
        mm[q]=1;
        break;

    }

}

cnt=0;

for (i=0;i<n;i++) if (mm[i]==0) cnt++;
cout << cnt <<' ';
for (i=0;i<n;i++) if (mm[i]==0) cout << i+1 <<' ';
//cin >> i;

    return 0;
}


#include <iostream>
#include <stdio.h>
#include <math.h>

using namespace std;

int main()
{
int n,k;
int i,j;

int a[1001];
int b[1001];
int c[1001];
int mm[1001];
int cnt;
double sum,max,s1,s2,min;
int q,dd;

cin >> n >> k;

cnt=0;
sum=0;
for (i=0;i<n;i++)
    {
        cin >> a[i] >> b[i];
        if (b[i]==1) cnt++;
        sum+=a[i];
    }

//

for (i=0;i<n;i++)
    {
        c[i]=-1;
        mm[i]=0;
}

dd=cnt;
if (cnt>k) dd=k;
s1=0;

max=-1;
for (i=0;i<dd;i++)
{
    max=0;
    q=-1;
    for (j=0;j<n;j++)
    {
        if (mm[j]!=0) continue;
        if (b[j]!=1) continue;
        if (a[j]>max)
        {
            q=j;
            max=a[j];
        }
    }
    mm[q]=1;
    c[i]=q;
    s1=s1+max;
}

if (dd==k)
{
    mm[q]=0;
    s1=s1-max;

    min=1500000000;
    for (i=0;i<n;i++)
    {
        if (mm[i]!=0) continue;
        if (a[i]<min) min = a[i];
    }

    s1=s1+min;
    dd--;
}
s2=sum-s1/2;
s1=floor(s2);
//cout.precision(2);
cout <<s2 ;

if (s1==s2) cout<<'.'<<'0'<< endl;
else cout << endl;

for (i=0;i<dd;i++)
{
    cout << 1 <<' '<<c[i]+1<<endl;
}
//
//put in
for (i=dd;i<k-1;i++)
{
    cout << 1 <<' ';
    for (j=0;j<n;j++)
    {
        if (mm[j]!=0) continue;
        q=j;
        cout << q+1 <<endl;
        mm[q]=1;
        break;

    }

}

cnt=0;

for (i=0;i<n;i++) if (mm[i]==0) cnt++;
cout << cnt <<' ';
for (i=0;i<n;i++) if (mm[i]==0) cout << i+1 <<' ';
//cin >> i;

    return 0;
}


#include <iostream>
#include <stdio.h>
#include <math.h>

using namespace std;

int main()
{
int n,k;
int i,j;

int a[1001];
int b[1001];
int c[1001];
int mm[1001];
int cnt;
double sum,max,s1,s2,min;
int q,dd;

cin >> n >> k;

cnt=0;
sum=0;
for (i=0;i<n;i++)
    {
        cin >> a[i] >> b[i];
        if (b[i]==1) cnt++;
        sum+=a[i];
    }

//

for (i=0;i<n;i++)
    {
        c[i]=-1;
        mm[i]=0;
}

dd=cnt;
if (cnt>k) dd=k;
s1=0;

max=-1;
for (i=0;i<dd;i++)
{
    max=0;
    q=-1;
    for (j=0;j<n;j++)
    {
        if (mm[j]!=0) continue;
        if (b[j]!=1) continue;
        if (a[j]>max)
        {
            q=j;
            max=a[j];
        }
    }
    mm[q]=1;
    c[i]=q;
    s1=s1+max;
}

if (dd==k)
{
    mm[q]=0;
    s1=s1-max;

    min=1500000000;
    for (i=0;i<n;i++)
    {
        if (mm[i]!=0) continue;
        if (a[i]<min) min = a[i];
    }

    s1=s1+min;
    dd--;
}
s2=sum-s1/2;
s1=floor(s2);
//cout.precision(2);
cout.precision(1);
cout.setf(ios::fixed);
cout<<s2 <<endl;

for (i=0;i<dd;i++)
{
    cout << 1 <<' '<<c[i]+1<<endl;
}
//
//put in
for (i=dd;i<k-1;i++)
{
    cout << 1 <<' ';
    for (j=0;j<n;j++)
    {
        if (mm[j]!=0) continue;
        q=j;
        cout << q+1 <<endl;
        mm[q]=1;
        break;

    }

}

cnt=0;

for (i=0;i<n;i++) if (mm[i]==0) cnt++;
cout << cnt <<' ';
for (i=0;i<n;i++) if (mm[i]==0) cout << i+1 <<' ';
//cin >> i;

    return 0;
}


#include <iostream>
#include <stdio.h>
#include <math>

using namespace std;

int main()
{
int n,k;
int i,j;

int a[1001];
int b[1001];
int c[1001];
int mm[1001];
int cnt;
double sum,max,s1,s2,min;
int q,dd;

cin >> n >> k;

cnt=0;
sum=0;
for (i=0;i<n;i++)
    {
        cin >> a[i] >> b[i];
        if (b[i]==1) cnt++;
        sum+=a[i];
    }

//

for (i=0;i<n;i++)
    {
        c[i]=-1;
        mm[i]=0;
}

dd=cnt;
if (cnt>k) dd=k;
s1=0;

max=-1;
for (i=0;i<dd;i++)
{
    max=0;
    q=-1;
    for (j=0;j<n;j++)
    {
        if (mm[j]!=0) continue;
        if (b[j]!=1) continue;
        if (a[j]>max)
        {
            q=j;
            max=a[j];
        }
    }
    mm[q]=1;
    c[i]=q;
    s1=s1+max;
}

if (dd==k)
{
    mm[q]=0;
    s1=s1-max;

    min=1500000000;
    for (i=0;i<n;i++)
    {
        if (mm[i]!=0) continue;
        if (a[i]<min) min = a[i];
    }

    s1=s1+min;
    dd--;
}
s2=sum-s1/2;
s1=floor(s2);
cout.precision(2);
cout <<s2 ;

if (s1==s2) cout<<'.'<<'0'<< endl;
else cout << endl;

for (i=0;i<dd;i++)
{
    cout << 1 <<' '<<c[i]+1<<endl;
}
//
//put in
for (i=dd;i<k-1;i++)
{
    cout << 1 <<' ';
    for (j=0;j<n;j++)
    {
        if (mm[j]!=0) continue;
        q=j;
        cout << q+1 <<endl;
        mm[q]=1;
        break;

    }

}

cnt=0;

for (i=0;i<n;i++) if (mm[i]==0) cnt++;
cout << cnt <<' ';
for (i=0;i<n;i++) if (mm[i]==0) cout << i+1 <<' ';
//cin >> i;

    return 0;
}


// rc.cpp
//

#include <math.h>
#include <string.h>

#include <fstream>
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <algorithm>
#include <numeric>

using namespace std;

typedef unsigned char uchar;
typedef unsigned int uint;
typedef unsigned __int64 uint64;

#define PI 3.1415926535897932384626433832795
#define EPS 1E-8

pair<uint, uint> t[1000],
				 p[1000];
int pn,
	tn;

int main(int argc, char* argv[])
{
	int n, k;
	cin >> n >> k;

	for (int i = 0; i < n; ++i)
	{
		uint c, w;
		cin >> c >> w;
		if (1 == w)
			t[tn++] = make_pair(c, i + 1);
		else
			p[pn++] = make_pair(c, i + 1);
	}

	sort(t, t + tn, greater<pair<uint, uint>>());
	sort(p, p + pn, greater<pair<uint, uint>>());

	double res = 0;
	int j = 0;
	for (; j < tn - 1 && j < k - 1; ++j)
		res += (double)t[j].first / 2.;

	for (; j < tn; ++j)
		res += t[j].first;

	for (int i = 0; i < pn; ++i)
		res += p[i].first;

	if (j >= k - 1)
	{
		if (pn && p[pn - 1].first < t[tn - 1].first)
			res -= (double)p[pn - 1].first / 2.;
		else
			res -= (double)t[tn - 1].first / 2.;
	}
	else if (tn)
		res -= (double)t[tn - 1].first / 2.;
	printf("%.1f\n", res);

	j = 0;
	for (; j < tn - 1 && j < k - 1; ++j)
		cout << 1 << " " << t[j].second << endl;

	if (j == k - 1)
	{
		cout << tn - j + pn;

		for (; j < tn; ++j)
			cout << " " << t[j].second;

		for (int i = 0; i < pn; ++i)
			cout << " " << p[i].second;
	}
	else
	{
		cout << 1 << " " << t[j].second << endl;
		++j;
		for (; j < k - 1; ++j)
			cout << 1 << " " << p[j - tn].second << endl;

		cout << pn - j + tn;
		for (int i = j - tn; i < pn; ++i)
			cout << " " << p[i].second;
	}
	cout << endl;

	return 0;
}