// 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 - 1; ++j)
		res += t[j].first;

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

	if (tn)
		res += (double)t[j].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;

		if (tn)
			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;
}


// 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
	{
		if (tn)
		{
			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;
}


// 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 - 1; ++j)
		res += t[j].first;

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

	if (tn)
		res += (double)t[j].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;
}


// 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];
uint pn,
	 tn;

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

	for (uint 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;
	uint j = 0;
	for (; j < tn - 1 && j < k - 1; ++j)
		res += (double)t[j].first / 2.;

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

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

	res += (double)t[j].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 << " " << t[j].second;
		for (uint 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 (uint i = j - tn; i < pn; ++i)
			cout << " " << p[i].second;
	}
	cout << endl;

	return 0;
}


#pragma comment(linker, "/stack:1000000")

#include <string>
#include <vector>
#include <map>
#include <list>
#include <iterator>
#include <set>
#include <queue>
#include <iostream>
#include <sstream>
#include <stack>
#include <deque>
#include <cmath>
#include <memory.h>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <algorithm>
#include <utility>

using namespace std;

#define FOR(i, a, b) for(int i = a; i < b; ++i)
#define RFOR(i, b, a) for(int i = b - 1; i >= a; --i)
#define REP(i, N) FOR(i, 0, N)
#define RREP(i, N) RFOR(i, N, 0)

#define MIN(A, B) ((A) < (B) ? (A) : (B))
#define MAX(A, B) ((A) > (B) ? (A) : (B))
#define ABS(A) ((A) < 0 ? (-(A)) : (A))
#define ALL(V) V.begin(), V.end()
#define SIZE(V) (int)V.size()
#define pb push_back
#define mp make_pair
#define EPS 1e-7
#define Pi 3.14159265358979
#define FILL(a,v) memset(a,v,sizeof(a))

typedef long long Long;
typedef unsigned long long ULong;
typedef unsigned int Uint;
typedef unsigned char Uchar;
typedef vector <int> VI;
typedef pair <int, int> PII;

const int MAXN=1111;

struct Good
{
    Long cost;
    int type;
    int id;

    bool operator<(const Good& g) const
    {
        return cost < g.cost;
    }
};

vector<Good> a[2];

struct Triple
{
    int x,y,z;

    Triple(int x = 0,int y = 0,int z = 0)
    {
        this->x=x;
        this->y=y;
        this->z=z;
    }
};

int n,k;

vector<Good> ans[MAXN];
bool has[MAXN];

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

    scanf("%d%d",&n,&k);
    Long res=0;
    REP(i,n)
    {
        Good g;
        scanf("%I64d%d",&g.cost,&g.type);
        g.cost*=2;
        g.type = g.type == 1 ? 1 : 0;
        g.id = i;

        res+=g.cost;

        a[g.type].push_back(g);
    }

    sort(ALL(a[1]));
    reverse(ALL(a[1]));

    sort(ALL(a[0]));

    int beg = min((int)a[1].size(),k);

    REP(i,beg)
    {
        ans[i].push_back(a[1][i]);
        has[i] = true;
    }

    if (beg == k)
    {
        FOR(i,beg,(int)a[1].size())
            ans[k-1].push_back(a[1][i]);
        REP(i,(int)a[0].size())
            ans[k-1].push_back(a[0][i]);
    } else
    {
        int cur=0;
        FOR(i,beg,k)
        {
            ++cur;
            ans[i].push_back(a[0][i-beg]);
        }

        FOR(i,cur,(int)a[0].size())
            ans[k-1].push_back(a[0][i]);
    }

    REP(i,k)
    {
        sort(ALL(ans[i]));
        if (has[i])
            res-=ans[i][0].cost/2;
    }

    printf("%I64d.%d\n",res/2,(res%2)*5);

    REP(i,k)
    {
        printf("%d",ans[i].size());
        REP(j,(int)ans[i].size())
            printf(" %d",ans[i][j].id + 1);
        puts("");
    }

    return 0;
}


#pragma comment(linker, "/stack:1000000")

#include <string>
#include <vector>
#include <map>
#include <list>
#include <iterator>
#include <set>
#include <queue>
#include <iostream>
#include <sstream>
#include <stack>
#include <deque>
#include <cmath>
#include <memory.h>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <algorithm>
#include <utility>

using namespace std;

#define FOR(i, a, b) for(int i = a; i < b; ++i)
#define RFOR(i, b, a) for(int i = b - 1; i >= a; --i)
#define REP(i, N) FOR(i, 0, N)
#define RREP(i, N) RFOR(i, N, 0)

#define MIN(A, B) ((A) < (B) ? (A) : (B))
#define MAX(A, B) ((A) > (B) ? (A) : (B))
#define ABS(A) ((A) < 0 ? (-(A)) : (A))
#define ALL(V) V.begin(), V.end()
#define SIZE(V) (int)V.size()
#define pb push_back
#define mp make_pair
#define EPS 1e-7
#define Pi 3.14159265358979
#define FILL(a,v) memset(a,v,sizeof(a))

typedef long long Long;
typedef unsigned long long ULong;
typedef unsigned int Uint;
typedef unsigned char Uchar;
typedef vector <int> VI;
typedef pair <int, int> PII;

const int MAXN=1111;

struct Good
{
    Long cost;
    int type;
    int id;

    bool operator<(const Good& g) const
    {
        return cost < g.cost;
    }
};

vector<Good> a[2];

struct Triple
{
    int x,y,z;

    Triple(int x = 0,int y = 0,int z = 0)
    {
        this->x=x;
        this->y=y;
        this->z=z;
    }
};

int n,k;

vector<Good> ans[MAXN];
bool has[MAXN];

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

    scanf("%d%d",&n,&k);
    Long res=0;
    REP(i,n)
    {
        Good g;
        scanf("%I64d%d",&g.cost,&g.type);
        g.cost*=2;
        g.type = g.type == 1 ? 1 : 0;
        g.id = i;

        res+=g.cost;

        a[g.type].push_back(g);
    }

    sort(ALL(a[1]));
    reverse(ALL(a[1]));

    sort(ALL(a[0]));

    int beg = min((int)a[1].size(),k);

    REP(i,beg)
    {
        ans[i].push_back(a[1][i]);
        has[i] = true;
    }

    if (beg == k)
    {
        FOR(i,beg,(int)ans[1].size())
            ans[k-1].push_back(ans[1][i]);
        REP(i,(int)ans[0].size())
            ans[k-1].push_back(ans[0][i]);
    } else
    {
        int cur=0;
        FOR(i,beg,k)
        {
            ++cur;
            ans[i].push_back(a[0][i-beg]);
        }

        FOR(i,cur,(int)a[0].size())
            ans[k-1].push_back(a[0][i]);
    }

    REP(i,k)
    {
        sort(ALL(ans[i]));
        if (has[i])
            res-=ans[i][0].cost/2;
    }

    printf("%I64d.%d\n",res/2,(res%2)*5);

    REP(i,k)
    {
        printf("%d",ans[i].size());
        REP(j,(int)ans[i].size())
            printf(" %d",ans[i][j].id + 1);
        puts("");
    }

    return 0;
}


#pragma comment(linker, "/stack:1000000")

#include <string>
#include <vector>
#include <map>
#include <list>
#include <iterator>
#include <set>
#include <queue>
#include <iostream>
#include <sstream>
#include <stack>
#include <deque>
#include <cmath>
#include <memory.h>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <algorithm>
#include <utility>

using namespace std;

#define FOR(i, a, b) for(int i = a; i < b; ++i)
#define RFOR(i, b, a) for(int i = b - 1; i >= a; --i)
#define REP(i, N) FOR(i, 0, N)
#define RREP(i, N) RFOR(i, N, 0)

#define MIN(A, B) ((A) < (B) ? (A) : (B))
#define MAX(A, B) ((A) > (B) ? (A) : (B))
#define ABS(A) ((A) < 0 ? (-(A)) : (A))
#define ALL(V) V.begin(), V.end()
#define SIZE(V) (int)V.size()
#define pb push_back
#define mp make_pair
#define EPS 1e-7
#define Pi 3.14159265358979
#define FILL(a,v) memset(a,v,sizeof(a))

typedef long long Long;
typedef unsigned long long ULong;
typedef unsigned int Uint;
typedef unsigned char Uchar;
typedef vector <int> VI;
typedef pair <int, int> PII;

const int MAXN=1111;

struct Good
{
    Long cost;
    int type;
    int id;

    bool operator<(const Good& g) const
    {
        return cost < g.cost;
    }
} a[MAXN];

struct Triple
{
    int x,y,z;

    Triple(int x = 0,int y = 0,int z = 0)
    {
        this->x=x;
        this->y=y;
        this->z=z;
    }
};

Long res[MAXN][MAXN][2];
Triple par[MAXN][MAXN][2];
int n,k;

VI ans[MAXN];

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

    scanf("%d%d",&n,&k);
    REP(i,n)
    {
        scanf("%I64d%d",&a[i].cost,&a[i].type);
        a[i].cost*=2;
        a[i].type = a[i].type == 1 ? 1 : 0;
        a[i].id = i;
    }

    sort(a,a+n);
    reverse(a,a+n);

    memset(res,-1,sizeof(res));
    int wasT = a[0].type;
    res[0][0][wasT] = wasT ? a[0].cost / 2 : a[0].cost;

    REP(i,n-1)
    {
        REP(j,k)
        {
            REP(was,2)
            {
                if (res[i][j][was] == -1)
                    continue;

                int nx;
                if (was)
                {
                    nx = res[i][j][1] + a[i].cost/2 + a[i+1].cost/2;
                    if (res[i+1][j][1] == -1 || res[i+1][j][1] > nx)
                    {
                        res[i+1][j][1] = nx;
                        par[i+1][j][1] = Triple(i,j,was);
                    }

                    nx = res[i][j][1] + (a[i+1].type ? a[i+1].cost/2 : a[i+1].cost);
                    if (res[i+1][j+1][a[i+1].type] == -1 || res[i+1][j+1][a[i+1].type] > nx)
                    {
                        res[i+1][j+1][a[i+1].type] = nx;
                        par[i+1][j+1][a[i+1].type] = Triple(i,j,was);
                    }
                } else
                {
                    if (a[i+1].type)
                    {
                        nx = res[i][j][0] + a[i+1].cost/2;
                        if (res[i+1][j][1] == -1 || res[i+1][j][1] > nx)
                        {
                            res[i+1][j][1] = nx;
                            par[i+1][j][1] = Triple(i,j,was);
                        }

                        nx = res[i][j][0] + a[i+1].cost/2;
                        if (res[i+1][j+1][1] == -1 || res[i+1][j+1][1] > nx)
                        {
                            res[i+1][j+1][1] = nx;
                            par[i+1][j+1][1] = Triple(i,j,was);
                        }
                    } else
                    {
                        nx = res[i][j][0] + a[i+1].cost;
                        if (res[i+1][j][0] == -1 || res[i+1][j][0] > nx)
                        {
                            res[i+1][j][0] = nx;
                            par[i+1][j][0] = Triple(i,j,was);
                        }

                        nx = res[i][j][0] + a[i+1].cost;
                        if (res[i+1][j+1][0] == -1 || res[i+1][j+1][0] > nx)
                        {
                            res[i+1][j+1][0] = nx;
                            par[i+1][j+1][0] = Triple(i,j,was);
                        }
                    }
                }
            }
        }
    }

    int i = n-1,j = k-1,was;

    if (res[i][j][0] == -1)
        was = 1; else
    if (res[i][j][1] == -1)
        was = 0; else
    if (res[i][j][0] < res[i][j][1])
        was = 0; else
        was = 1;

    printf("%I64d.%d\n", res[i][j][was]/2, (res[i][j][was]%2)*5);

    REP(it,n)
    {
        Triple cur = par[i][j][was];

        ans[j].push_back(i);

        i = cur.x;
        j = cur.y;
        was = cur.z;
    }

    REP(i,k)
    {
        printf("%d",ans[i].size());
        sort(ALL(ans[i]));
        REP(j,(int)ans[i].size())
            printf(" %d",a[ans[i][j]].id + 1);
        puts("");
    }

    return 0;
}


#pragma comment(linker, "/stack:64000000")
#include <algorithm>
#include <iostream>
#include <cassert>
#include <climits>
#include <utility>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <memory.h>
#include <vector>
#include <bitset>
#include <string>
#include <deque>
#include <queue>
#include <ctime>
#include <set>
#include <map>
#include <deque>
#include <stack>
#include <cmath>
using namespace std;

typedef long long ll;
typedef long double ld;
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define ford(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define for1(i, n) for (int i = 1; i <= int(n); i++)
#define fore(i, l, r) for (int i = int(l); i < int(r); i++)
#define all(a) (a).begin(), (a).end()
#define sz(a) int((a).size())
#define pb push_back
#define pii pair <int, int>
#define vi vector <int>
#define mp make_pair

template <typename X> inline X abs (const X &a) {return a < 0? -a: a;}
template <typename X> inline X sqr (const X &a) {return a * a;}

const int INF = INT_MAX / 2;
const ll INF64 = LLONG_MAX / 2LL;
const ld EPS = 1E-9, PI = 3.1415926535897932384626433832795;

const int N = 1000 + 13;

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

    int n, m;
    vector <pii> v, u;

    cin >> n >> m;

    forn (i, n)
    {
        int c, t;
        cin >> c >> t;

        if (t == 1)
        {
            v.pb (mp (c, i));
        }
        else
        {
            u.pb (mp (c, i));
        }
    }

    sort (all (v));
    sort (all (u));

    reverse (all (v));
    reverse (all (u));

    int sz = 0;
    vector <int> ans[N];

    ld res = 0.0;

    forn (i, min (m - 1, sz (v)))
    {
        ans[sz++].pb (v[i].second);
        res += ld (v[i].first) / 2.0;
    }

    if (sz + 1 == m)
    {
        bool half = m - 1 < sz (v);
        vector <pii> rem;

        for (int i = m - 1; i < sz (v); i++)
            rem.pb (v[i]);

        forn (i, sz (u))
            rem.pb (u[i]);

        sort (all (rem));
        if (half)
            res += ld (rem[0].first) / 2.0;
        else
            res += ld (rem[0].first);

        ans[sz].pb (rem[0].second);
        for (int i = 1; i < sz (rem); i++)
        {
            res += ld (rem[i].first);
            ans[sz].pb (rem[i].second);
        }

        sz++;
    }
    else
    {
        forn (i, sz (u))
        {
            res += u[i].first;
            ans[sz].pb (u[i].second);
            sz = min (m - 1, sz + 1);
        }
    }

    printf ("%.1lf\n", res);
    forn (i, m)
    {
        assert (sz (ans[i]) > 0);
        printf ("%d ", sz (ans[i]));
        forn (j, sz (ans[i]))
            printf ("%d ", ans[i][j] + 1);
        puts("");
    }

    return 0;
}


#pragma comment(linker, "/stack:64000000")
#include <algorithm>
#include <iostream>
#include <cassert>
#include <climits>
#include <utility>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <memory.h>
#include <vector>
#include <bitset>
#include <string>
#include <deque>
#include <queue>
#include <ctime>
#include <set>
#include <map>
#include <deque>
#include <stack>
#include <cmath>
using namespace std;

typedef long long ll;
typedef long double ld;
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define ford(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define for1(i, n) for (int i = 1; i <= int(n); i++)
#define fore(i, l, r) for (int i = int(l); i < int(r); i++)
#define all(a) (a).begin(), (a).end()
#define sz(a) int((a).size())
#define pb push_back
#define pii pair <int, int>
#define vi vector <int>
#define mp make_pair

template <typename X> inline X abs (const X &a) {return a < 0? -a: a;}
template <typename X> inline X sqr (const X &a) {return a * a;}

const int INF = INT_MAX / 2;
const ll INF64 = LLONG_MAX / 2LL;
const ld EPS = 1E-9, PI = 3.1415926535897932384626433832795;

const int N = 1000 + 13;

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

    int n, m;
    vector <pii> v, u;

    cin >> n >> m;

    forn (i, n)
    {
        int c, t;
        cin >> c >> t;

        if (t == 1)
        {
            v.pb (mp (c, i));
        }
        else
        {
            u.pb (mp (c, i));
        }
    }

    sort (all (v));
    sort (all (u));

    reverse (all (v));
    reverse (all (u));

    int sz = 0;
    vector <int> ans[N];

    ld res = 0.0;

    forn (i, min (m - 1, sz (v)))
    {
        ans[sz++].pb (v[i].second);
        res += ld (v[i].first) / 2.0;
    }

    if (sz + 1 == m)
    {
        bool half = m - 1 < sz (v);
        vector <pii> rem;

        for (int i = m - 1; i < sz (v); i++)
            rem.pb (v[i]);

        forn (i, sz (u))
            rem.pb (u[i]);

        sort (all (rem));
        res += ld (rem[0].first) / 2.0;

        ans[sz].pb (rem[0].second);
        for (int i = 1; i < sz (rem); i++)
        {
            res += ld (rem[i].first);
            ans[sz].pb (rem[i].second);
        }

        sz++;
    }
    else
    {
        forn (i, sz (u))
        {
            res += u[i].first;
            ans[sz].pb (u[i].second);
            sz = min (m - 1, sz + 1);
        }
    }

    printf ("%.1lf\n", res);
    forn (i, m)
    {
        assert (sz (ans[i]) > 0);
        printf ("%d ", sz (ans[i]));
        forn (j, sz (ans[i]))
            printf ("%d ", ans[i][j] + 1);
        puts("");
    }

    return 0;
}


#define _CRT_SECURE_NO_DEPRECATE

#include <string>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <memory.h>
#include <string.h>

using namespace std;

#define pb push_back
#define pf push_front
#define mp make_pair
#define fi(a, b) for(i=a; i<=b; i++)
#define fj(a, b) for(j=a; j<=b; j++)
#define fo(a, b) for(o=a; o<=b; o++)
#define fdi(a, b) for(i=a; i>=b; i--)
#define fdj(a, b) for(j=a; j>=b; j--)
#define fdo(a, b) for(o=a; o>=b; o--)
#define ZERO(x) memset(x, 0, sizeof(x));
#define COPY(x, y) memcpy(x, y, sizeof(y));
#define SIZE(x) (int)x.size()
#define LEN(x) (int)x.length()

typedef long long int64;
typedef pair<int64, int64> pii;
typedef vector<int64> vi;
typedef vector<pii> vpii;

#define MAX 10010

int64 n, k;

vector <pii> t1, t2;

int64 ans;
vector <int> ansv[MAX];
int64 ansq;

int main() {
    int64 c1, c2;
    int64 c, t;
    int64 i, j;
#ifdef _DEBUG
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
#endif
    scanf("%I64d %I64d", &n, &k);
    fi(1, n) {
        scanf("%I64d %I64d", &c, &t);
        c *= 10;
        if (t == 1) {
            t1.pb(mp(c, i));
        } else {
            t2.pb(mp(c, i));
        }
    }

    sort(t1.begin(), t1.end());
    sort(t2.begin(), t2.end());

    fdi(SIZE(t1) - 1, max(0ll, SIZE(t1) - k + 1)) {
        ans += t1[i].first / 2;
        ansq++;
        ansv[ansq].pb(t1[i].second);
    }

    c1 = SIZE(t1) - k;
    c2 = SIZE(t2) - 1;

    while (ansq < k - 1) {
        ansq++;
        ans += t2[c2].first;
        ansv[ansq].pb(t2[c2].second);
        c2--;
    }

    ansq++;

    if (c1 >= 0 && c2 >= 0) {
        ans -= min(t1[0].first, t2[0].first) / 2;
    } else if (c1 >= 0) {
        ans -= t1[0].first / 2;
    }

    while (c1 >= 0) {
        ans += t1[c1].first;
        ansv[ansq].pb(t1[c1].second);
        c1--;
    }

    while (c2 >= 0) {
        ans += t2[c2].first;
        ansv[ansq].pb(t2[c2].second);
        c2--;
    }

    printf("%I64d.%I64d\n", ans / 10, ans % 10);
    fi(1, k) {
        printf("%d ", SIZE(ansv[i]));
        fj(0, SIZE(ansv[i]) - 1) {
            printf("%d ", ansv[i][j]);
        }
        printf("\n");
    }

    return 0;
}


#define _CRT_SECURE_NO_DEPRECATE

#include <string>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <memory.h>
#include <string.h>

using namespace std;

#define pb push_back
#define pf push_front
#define mp make_pair
#define fi(a, b) for(i=a; i<=b; i++)
#define fj(a, b) for(j=a; j<=b; j++)
#define fo(a, b) for(o=a; o<=b; o++)
#define fdi(a, b) for(i=a; i>=b; i--)
#define fdj(a, b) for(j=a; j>=b; j--)
#define fdo(a, b) for(o=a; o>=b; o--)
#define ZERO(x) memset(x, 0, sizeof(x));
#define COPY(x, y) memcpy(x, y, sizeof(y));
#define SIZE(x) (int)x.size()
#define LEN(x) (int)x.length()

typedef long long int64;
typedef pair<int64, int64> pii;
typedef vector<int64> vi;
typedef vector<pii> vpii;

#define MAX 10010

int64 n, k;

vector <pii> t1, t2;

int64 ans;
vector <int> ansv[MAX];
int64 ansq;

int main() {
    int64 c1, c2;
    int64 c, t;
    int64 i, j;
#ifdef _DEBUG
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
#endif
    scanf("%I64d %I64d", &n, &k);
    fi(1, n) {
        scanf("%I64d %I64d", &c, &t);
        c *= 10;
        if (t == 1) {
            t1.pb(mp(c, i));
        } else {
            t2.pb(mp(c, i));
        }
    }

    fdi(SIZE(t1) - 1, max(0ll, SIZE(t1) - k + 1)) {
        ans += t1[i].first / 2;
        ansq++;
        ansv[ansq].pb(t1[i].second);
    }

    c1 = SIZE(t1) - k;
    c2 = SIZE(t2) - 1;

    while (ansq < k - 1) {
        ansq++;
        ans += t2[c2].first;
        ansv[ansq].pb(t2[c2].second);
        c2--;
    }

    ansq++;

    if (c1 >= 0 && c2 >= 0) {
        ans -= min(t1[0].first, t2[0].first) / 2;
    } else if (c1 >= 0) {
        ans -= t1[0].first / 2;
    }

    while (c1 >= 0) {
        ans += t1[c1].first;
        ansv[ansq].pb(t1[c1].second);
        c1--;
    }

    while (c2 >= 0) {
        ans += t2[c2].first;
        ansv[ansq].pb(t2[c2].second);
        c2--;
    }

    printf("%I64d.%I64d\n", ans / 10, ans % 10);
    fi(1, k) {
        printf("%d ", SIZE(ansv[i]));
        fj(0, SIZE(ansv[i]) - 1) {
            printf("%d ", ansv[i][j]);
        }
        printf("\n");
    }

    return 0;
}


#define _CRT_SECURE_NO_DEPRECATE

#include <string>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <memory.h>
#include <string.h>

using namespace std;

#define pb push_back
#define pf push_front
#define mp make_pair
#define fi(a, b) for(i=a; i<=b; i++)
#define fj(a, b) for(j=a; j<=b; j++)
#define fo(a, b) for(o=a; o<=b; o++)
#define fdi(a, b) for(i=a; i>=b; i--)
#define fdj(a, b) for(j=a; j>=b; j--)
#define fdo(a, b) for(o=a; o>=b; o--)
#define ZERO(x) memset(x, 0, sizeof(x));
#define COPY(x, y) memcpy(x, y, sizeof(y));
#define SIZE(x) (int)x.size()
#define LEN(x) (int)x.length()

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef long long int64;

#define MAX 1010

int n, k;

vector <pii> t1, t2;

double ans;
vector <int> ansv[MAX];
int ansq;

int main() {
    int c1, c2;
    int c, t;
    int i, j;
#ifdef _DEBUG
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
#endif
    scanf("%d %d", &n, &k);
    fi(1, n) {
        scanf("%d %d", &c, &t);
        if (t == 1) {
            t1.pb(mp(c, i));
        } else {
            t2.pb(mp(c, i));
        }
    }

    fdi(SIZE(t1) - 1, max(0, SIZE(t1) - k + 1)) {
        ans += (double)t1[i].first / 2;
        ansq++;
        ansv[ansq].pb(t1[i].second);
    }

    c1 = SIZE(t1) - k;
    c2 = SIZE(t2) - 1;

    while (ansq < k - 1) {
        ansq++;
        ans += t2[c2].first;
        ansv[ansq].pb(t2[c2].second);
        c2--;
    }

    ansq++;

    if (c1 >= 0 && c2 >= 0) {
        ans -= (double)min(t1[0].first, t2[0].first) / 2;
    } else if (c1 >= 0) {
        ans -= (double)t1[0].first / 2;
    }

    while (c1 >= 0) {
        ans += (double)t1[c1].first;
        ansv[ansq].pb(t1[c1].second);
        c1--;
    }

    while (c2 >= 0) {
        ans += (double)t2[c2].first;
        ansv[ansq].pb(t2[c2].second);
        c2--;
    }

    printf("%.1lf\n", ans);
    fi(1, k) {
        printf("%d ", SIZE(ansv[i]));
        fj(0, SIZE(ansv[i]) - 1) {
            printf("%d ", ansv[i][j]);
        }
        printf("\n");
    }

    return 0;
}


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

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned char byte;
typedef pair<int, int> pii;
#define forn(i,n) for (int i = 0; i < int(n); ++i)
#define mp make_pair

int readint() {
  int i;
  scanf("%d", &i);
  return i;
}

vector<pii> K, T;
vector<vector<int> > result;

int main() {
  int n = readint(), k = readint();
  ull sum = 0;
  forn (i, n) {
    int c = readint(), t = readint();
    sum += 2 * c;
    if (t == 1) T.push_back(make_pair(2 * c, i));
    else K.push_back(make_pair(2 * c, i));
  }
  result.resize(k);

  sort(K.begin(), K.end());
  sort(T.begin(), T.end());

  ull R = sum;
  if (T.size() >= k) {
    int first = T[0].first;
    if (!K.empty()) first = min(K[0].first, T[0].first);
    R -= first / 2;
    forn (i, K.size()) result[0].push_back(K[i].second);
    for (int i = 0; i <= int(T.size()) - k; ++i)
      result[0].push_back(T[i].second);
    forn (j, k -1) {
      int i = T.size() - 1 - j;
      result[j + 1].push_back(T[i].second);
      R -= T[i].first / 2;
    }

  } else {
    forn (i, T.size()) {
      result[i].push_back(T[i].second);
      R -= T[i].first / 2;
    }
    forn (j, K.size()) {
      int i = T.size() + j;
      if (i >= k) {
        result[T.size()].push_back(K[j].second);
      } else {
        result[i].push_back(K[j].second);
      }
    }
  }

  printf ("%d", R / 2);
  printf(".");
  printf("%d\n", (R % 2) ? 5 : 0);
  forn (i, k) {
    printf("%d", result[i].size());
    forn (j, result[i].size())
      printf(" %d", result[i][j] + 1);
    printf("\n");
  }

  return 0;
}


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

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned char byte;
typedef pair<int, int> pii;
#define forn(i,n) for (int i = 0; i < int(n); ++i)
#define mp make_pair

int readint() {
  int i;
  scanf("%d", &i);
  return i;
}

vector<pii> K, T;
vector<vector<int> > result;

int main() {
  int n = readint(), k = readint();
  ull sum = 0;
  forn (i, n) {
    int c = readint(), t = readint();
    sum += 2 * c;
    if (t == 1) T.push_back(make_pair(2 * c, i));
    else K.push_back(make_pair(2 * c, i));
  }
  result.resize(k);

  sort(K.begin(), K.end());
  sort(T.begin(), T.end());

  ull R = sum;
  if (T.size() >= k) {
    int first = min(K[0].first, T[0].first);
    R -= first / 2;
    forn (i, K.size()) result[0].push_back(K[i].second);
    for (int i = 0; i <= int(T.size()) - k; ++i)
      result[0].push_back(T[i].second);
    forn (j, k -1) {
      int i = T.size() - 1 - j;
      result[j + 1].push_back(T[i].second);
      R -= T[i].first / 2;
    }

  } else {
    forn (i, T.size()) {
      result[i].push_back(T[i].second);
      R -= T[i].first / 2;
    }
    forn (j, K.size()) {
      int i = T.size() + j;
      if (i >= k) {
        result[T.size()].push_back(K[j].second);
      } else {
        result[i].push_back(K[j].second);
      }
    }
  }

  printf ("%d", R / 2);
  printf(".");
  printf("%d\n", (R % 2) ? 5 : 0);
  forn (i, k) {
    printf("%d", result[i].size());
    forn (j, result[i].size())
      printf(" %d", result[i][j] + 1);
    printf("\n");
  }

  return 0;
}


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

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned char byte;
typedef pair<int, int> pii;
#define forn(i,n) for (int i = 0; i < int(n); ++i)
#define mp make_pair

int readint() {
  int i;
  scanf("%d", &i);
  return i;
}

vector<pii> K, T;
vector<vector<int> > result;

int main() {
  int n = readint(), k = readint();
  ull sum = 0;
  forn (i, n) {
    int c = readint(), t = readint();
    sum += 2 * c;
    if (t == 1) T.push_back(make_pair(2 * c, i));
    else K.push_back(make_pair(2 * c, i));
  }
  result.resize(k);

  sort(K.begin(), K.end());
  sort(T.begin(), T.end());

  ull R = sum;
  if (T.size() >= k) {
    int first = T[0].first;
    if (!K.empty()) first = min(K[0].first, T[0].first);
    R -= first / 2;
    forn (i, K.size()) result[0].push_back(K[i].second);
    for (int i = 0; i <= int(T.size()) - k; ++i)
      result[0].push_back(T[i].second);
    forn (j, k -1) {
      int i = T.size() - 1 - j;
      result[j + 1].push_back(T[i].second);
      R -= T[i].first / 2;
    }

  } else {
    forn (i, T.size()) {
      result[i].push_back(T[i].second);
      R -= T[i].first / 2;
    }
    forn (j, K.size()) {
      int i = T.size() + j;
      if (i >= k) {
        result[T.size()].push_back(K[j].second);
      } else {
        result[i].push_back(K[j].second);
      }
    }
  }

  cout << (R / 2);
  printf(".");
  printf("%d\n", (R % 2) ? 5 : 0);
  forn (i, k) {
    printf("%d", result[i].size());
    forn (j, result[i].size())
      printf(" %d", result[i][j] + 1);
    printf("\n");
  }

  return 0;
}


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

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned char byte;
typedef pair<int, int> pii;
#define forn(i,n) for (int i = 0; i < int(n); ++i)
#define mp make_pair

int readint() {
  int i;
  scanf("%d", &i);
  return i;
}

vector<pii> K, T;
vector<vector<int> > result;

int main() {
  int n = readint(), k = readint();
  ull sum = 0;
  forn (i, n) {
    int c = readint(), t = readint();
    sum += 2 * c;
    if (t == 1) T.push_back(make_pair(2 * c, i));
    else K.push_back(make_pair(2 * c, i));
  }
  result.resize(k);

  sort(K.begin(), K.end());
  sort(T.begin(), T.end());

  ull R = sum;
  if (T.size() >= k) {
    int first = T[0].first;
    if (!K.empty()) first = min(K[0].first, T[0].first);
    R -= first / 2;
    forn (i, K.size()) result[0].push_back(K[i].second);
    for (int i = 0; i <= int(T.size()) - k; ++i)
      result[0].push_back(T[i].second);
    forn (j, k -1) {
      int i = T.size() - 1 - j;
      result[j + 1].push_back(T[i].second);
      R -= T[i].first / 2;
    }

  } else {
    forn (i, T.size()) {
      result[i].push_back(T[i].second);
      R -= T[i].first / 2;
    }
    forn (j, K.size()) {
      int i = T.size() + j;
      if (i >= k) {
        result[T.size()].push_back(K[j].second);
      } else {
        result[i].push_back(K[j].second);
      }
    }
  }

  cout << (R / 2) << endl;
  printf(".");
  printf("%d\n", (R % 2) ? 5 : 0);
  forn (i, k) {
    printf("%d", result[i].size());
    forn (j, result[i].size())
      printf(" %d", result[i][j] + 1);
    printf("\n");
  }

  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 <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;
}

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);
	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>tab[i].p)
			mi = tab[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 <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;
}

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);
	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;
	for (i=t1;i<tc;i++)
		res += tab[i].p;
	for (i=t2;i<kc;i++)
		res += kar[i].p;
	//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 <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+tc,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>tab[i].p)
			mi = tab[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 <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>tab[i].p)
			mi = tab[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 <fstream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <cstdio>
#include <cmath>
#include <memory.h>
#include <algorithm>
#include <queue>

using namespace std;

const int mm = 1010;
const double inf = 1e8;
int n,k;
deque<pair<int,int> > A, B;
vector<int> R[mm];
double res = 0;

int main() {
	//freopen("input.txt","r",stdin); // TODO: remove it !!!
	cin>>n>>k;
	for (int i=1; i<=n; i++) {
		int a,b; cin>>a>>b;
		if (b==1)
			A.push_back(make_pair(a, i));
		else
			B.push_back(make_pair(a, i));
	}
	sort(A.begin(), A.end());
	int T = A.size();
	int c = min(k-1,T);
	for (int i=0; i<c; i++) {
		res+= 0.5 * A[T-1-i].first;
		R[i].push_back(A[T-1-i].second);
		A.pop_back();
	}
	for (int i=0; i<A.size(); i++)
		B.push_back(A[i]);
	sort(B.begin(), B.end());
	for (int i=c; i<k-1; i++) {
		res += B[0].first;
		R[i].push_back(B[0].second);
		B.pop_front();
	}
	for (int i=0; i<B.size(); i++) {
		res+=B[i].first;
		R[k-1].push_back(B[i].second);
	}
	if (T>=k)
		res-= 0.5 * B[0].first;
	cout.precision(1);
	cout<<fixed<<res<<endl;
	for (int i=0; i<k; i++) {
		cout<<R[i].size();
		for (int j=0; j<R[i].size(); j++)
			cout<<" "<<R[i][j];
		cout<<endl;
	}
	return 0;
}


#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <cstdio>
#include <cmath>
#include <memory.h>
#include <algorithm>

using namespace std;

const int mm = 1010;
const double inf = 1e13;
int n,K;
pair<int, pair< int, int> > A[mm];
double f[mm][mm];
int p[mm][mm];

int main() {
	//freopen("input.txt","r",stdin); // TODO: remove it !!!
	cin>>n>>K;
	for (int i=1; i<=n; i++) {
		int a,b; cin>>a>>b;
		A[i] = make_pair(a, make_pair(b,i));
	}
	sort(A, A+n);
	for (int i=0; i<=n; i++)
		for (int j=0; j<=K; j++) {
			f[i][j] = inf;
			if (i==0 && j==0)
				f[i][j] = 0;
			if (i > 0 && j>0) {
				double sum = 0; bool isT = false;
				for (int k=i; k>0; k--) {
					sum += A[k].first;
					if (A[k].second.first == 1)
						isT = true;
					double score = sum + f[k-1][j-1];
					if (isT) score -= 0.5 * A[k].first;
					if (score < f[i][j]) {
						f[i][j] = score;
						p[i][j] = k-1;
					}
				}
			}
		}
	cout.precision(1);
	cout<<fixed<<f[n][K]<<endl;
	int i=n;
	for (int j=K; j>0; j--) {
		cout<<i-p[i][j];
		for (int k=p[i][j]+1; k<=i; k++)
			cout<<" "<<A[k].second.second;
		cout<<endl;
		i=p[i][j];
	}
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <string>
#include <hash_map>
#include <map>
#include <hash_set>
#include <unordered_map>
#include <set>
#include <stack>
#include <algorithm>
#include <sstream>
#include <queue>

using namespace std;
typedef long long LL;
#define mems(arr, val) memset(arr, val, sizeof(arr));
#define iterat(A) A.begin(), A.end()
#define forn(it, from, to) for(int it = from; it < to; ++it)
#define INF 2000000000
#define SIZE 1000009

int main()
{
	//freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
	int n,k;
	cin>>n>>k;
	vector<pair<LL, int>> chair;
	vector<pair<LL, int>> pen;
	LL minim = 999999999999999;
	forn(i, 0, n)
	{
		LL val, t;
		cin>>val>>t;
		if (t == 1)
		{
			chair.push_back(make_pair(val * 10, i + 1));
			minim = min(val * 10, minim);
		}
		else
		{
			pen.push_back(make_pair(val * 10, i + 1));
			minim = min(val * 10, minim);
		}
	}

	sort(iterat(chair));

	vector<vector<int>> ans(k);
	LL sum = 0;
	int i = 0;
	for (i = 0; i < k; ++i)
	{
		if (chair.size() > 0)
		{
			ans[i].push_back(chair.back().second);
			if (i != k - 1) sum += chair.back().first / 2; else sum += chair.back().first;
			chair.pop_back();
			continue;
		}
		else
		{
			break;
		}
	}

	if (i == k)
	{
		sum -= minim / 2;
		for (int j = 0; j < chair.size(); j++)
		{
			ans[k - 1].push_back(chair[j].second);
			sum += chair[j].first;
		}
		for (int j = 0; j < pen.size(); j++)
		{
			ans[k - 1].push_back(pen[j].second);
			sum += pen[j].first;
		}
	}
	else
	{
		for (int j = 0; i < k; j++)
		{
			ans[i].push_back(pen.back().second);
			sum += (pen.back().first);
			pen.pop_back();
			i++;
		}
		for (int j = 0; j < pen.size();)
		{
			ans[k - 1].push_back(pen.back().second);
			sum += (pen.back().first);
			pen.pop_back();
		}
	}

	cout<<sum / 10<<"."<<sum % 10<<endl;
	for (int i = 0; i < k; ++i)
	{
		cout<<ans[i].size()<<" ";
		for (int j = 0; j < ans[i].size(); ++j)
		{
			cout<<ans[i][j]<<" ";
		}

		cout<<endl;
	}

	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <string>
#include <hash_map>
#include <map>
#include <hash_set>
#include <unordered_map>
#include <set>
#include <stack>
#include <algorithm>
#include <sstream>
#include <queue>

using namespace std;
typedef long long LL;
#define mems(arr, val) memset(arr, val, sizeof(arr));
#define iterat(A) A.begin(), A.end()
#define forn(it, from, to) for(int it = from; it < to; ++it)
#define INF 2000000000
#define SIZE 1000009

int main()
{
	//freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
	int n,k;
	cin>>n>>k;
	vector<pair<LL, int>> chair;
	vector<pair<LL, int>> pen;
	LL minim = 999999999999999;
	forn(i, 0, n)
	{
		LL val, t;
		cin>>val>>t;
		if (t == 1)
		{
			chair.push_back(make_pair(val * 10, i + 1));
			minim = min(val * 10, minim);
		}
		else
		{
			pen.push_back(make_pair(val * 10, i + 1));
			minim = min(val * 10, minim);
		}
	}

	sort(iterat(chair));

	vector<vector<int>> ans(k);
	LL sum = 0;
	int i = 0;
	for (i = 0; i < k; ++i)
	{
		if (chair.size() > 0)
		{
			ans[i].push_back(chair.back().second);
			if (i != k - 1) sum += chair.back().first / 2; else sum += chair.back().first;
			chair.pop_back();
			continue;
		}
		else
		{
			break;
		}
	}

	if (i == k)
	{
		sum -= minim / 2;
		for (int j = 0; j < chair.size(); j++)
		{
			ans[k - 1].push_back(chair[j].second);
			sum += chair.back().first;
		}
		for (int j = 0; j < pen.size(); j++)
		{
			ans[k - 1].push_back(pen[j].second);
			sum += pen.back().first;
		}
	}
	else
	{
		for (int j = 0; i < k; j++)
		{
			ans[i].push_back(pen.back().second);
			sum += (pen.back().first);
			pen.pop_back();
			i++;
		}
		for (int j = 0; j < pen.size();)
		{
			ans[k - 1].push_back(pen.back().second);
			sum += (pen.back().first);
			pen.pop_back();
		}
	}

	cout<<sum / 10<<"."<<sum % 10<<endl;
	for (int i = 0; i < k; ++i)
	{
		cout<<ans[i].size()<<" ";
		for (int j = 0; j < ans[i].size(); ++j)
		{
			cout<<ans[i][j]<<" ";
		}

		cout<<endl;
	}

	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/STACK:64000000")
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <ctime>
#include <cmath>
#include <set>
#include <map>
#include <cassert>
#include <queue>
#include <deque>
#include <stack>
#include <sstream>
#include <cstring>
#include <string>
#include <functional>
#include <numeric>
#include <bitset>

using namespace std;

#define MP make_pair
#define all(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << ": " << x << endl;

const int INF = ((1 << 31) - 1);
const long long LLINF = (((1LL << 63) - 1LL));
const double eps = 1e-9;
const double PI = 3.14159265358979323846;

typedef long long ll;
typedef pair<int, int> pii;

const string PROBLEM_NAME = "task";

int main() {
    //freopen((PROBLEM_NAME + ".in").c_str(), "r", stdin);
    //freopen((PROBLEM_NAME + ".out").c_str(), "w", stdout);
    //freopen((PROBLEM_NAME + ".err").c_str(), "w", stderr);
	int n, b;
	cin >> n >> b;
	vector<pii> chair;
	vector<pii> pen;
	ll total = 0;
	for (int i = 0; i < n; ++i) {
		int a, b;
		scanf("%d%d", &a, &b);
		if (b == 1)
			chair.push_back(MP(a, i));
		else
			pen.push_back(MP(a, i));
		total += a;
	}
	sort(all(chair));reverse(all(chair));
	sort(all(pen));reverse(all(pen));
	vector<vector<int> > staff(b);
	ll doubleWin = 0;
	if (chair.size() >= b) {
		int last = chair.back().first;
		for (int i = 0; i < chair.size(); ++i) {
			if (i <= b - 2) {
				doubleWin += chair[i].first;
			}
			staff[min(i, b - 1)].push_back(chair[i].second);
		}
		for (int i = 0; i < pen.size(); ++i) {
			staff[b - 1].push_back(pen[i].second);
			last = min(last, pen[i].first);
		}
		doubleWin += last;
	} else {
		for (int i = 0; i < chair.size(); ++i) {
			doubleWin += chair[i].first;
			staff[i].push_back(chair[i].second);
		}
		int x = chair.size();
		for (int i = 0; i < pen.size(); ++i) {
			staff[min(x++, b - 1)].push_back(pen[i].second);
		}
	}
	printf("%0.1lf\n", 1.0 * total - 0.5 * doubleWin);
	for (int i = 0; i < b; ++i) {
		printf("%d ", int(staff[i].size()));
		for (int j = 0; j < staff[i].size(); ++j) {
			printf("%d ", staff[i][j] + 1);
		}
		printf("\n");
	}
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/STACK:64000000")
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <ctime>
#include <cmath>
#include <set>
#include <map>
#include <cassert>
#include <queue>
#include <deque>
#include <stack>
#include <sstream>
#include <cstring>
#include <string>
#include <functional>
#include <numeric>
#include <bitset>

using namespace std;

#define MP make_pair
#define all(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << ": " << x << endl;

const int INF = ((1 << 31) - 1);
const long long LLINF = (((1LL << 63) - 1LL));
const double eps = 1e-9;
const double PI = 3.14159265358979323846;

typedef long long ll;
typedef pair<int, int> pii;

const string PROBLEM_NAME = "task";

int main() {
    //freopen((PROBLEM_NAME + ".in").c_str(), "r", stdin);
    //freopen((PROBLEM_NAME + ".out").c_str(), "w", stdout);
    //freopen((PROBLEM_NAME + ".err").c_str(), "w", stderr);
	int n, b;
	cin >> n >> b;
	vector<pii> chair;
	vector<pii> pen;
	ll total = 0;
	for (int i = 0; i < n; ++i) {
		int a, b;
		scanf("%d%d", &a, &b);
		if (b == 1)
			chair.push_back(MP(a, i));
		else
			pen.push_back(MP(a, i));
		total += a;
	}
	sort(all(chair));reverse(all(chair));
	sort(all(pen));reverse(all(pen));
	vector<vector<int> > staff(b);
	ll doubleWin = 0;
	if (chair.size() >= b) {
		for (int i = 0; i < chair.size(); ++i) {
			if (i <= b - 1) {
				doubleWin += chair[i].first;
			}
			staff[min(i, b - 1)].push_back(chair[i].second);
		}
		for (int i = 0; i < pen.size(); ++i) {
			staff[b - 1].push_back(pen[i].second);
		}
	} else {
		for (int i = 0; i < chair.size(); ++i) {
			doubleWin += chair[i].first;
			staff[i].push_back(chair[i].second);
		}
		int x = chair.size();
		for (int i = 0; i < pen.size(); ++i) {
			staff[min(x++, b - 1)].push_back(pen[i].second);
		}
	}
	printf("%0.1lf\n", 1.0 * total - 0.5 * doubleWin);
	for (int i = 0; i < b; ++i) {
		printf("%d ", int(staff[i].size()));
		for (int j = 0; j < staff[i].size(); ++j) {
			printf("%d ", staff[i][j] + 1);
		}
		printf("\n");
	}
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#ifndef _DEBUG
#define NDEBUG
#endif
#include <cstdio>
#include <cmath>
#include <cctype>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <utility>
#include <string>
#include <map>
#include <set>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <numeric>
#include <functional>
using namespace std;

#define C(_a) memset(_a, 0, sizeof(_a))
#define ALL(_obj) (_obj).begin(),(_obj).end()
#define FORB(_i, _a, _b) for((_i) = (_a); (_i) < (_b); ++(_i))
#define FOR(_i, _n) FORB(_i, 0, _n)
#define FORS(_i, _obj) FOR(_i, (_obj).size())
#define ADJ(_i, _v) for((_i) = kick[_v]; (_i) >= 0; (_i) = foll[_i])
#define MP make_pair
#define PB push_back

typedef long long i64;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<i64, int> pi64i;

template<typename T> inline void remin(T& cur, const T& prop) { if (cur > prop) cur = prop; }
template<typename T> inline void remax(T& cur, const T& prop) { if (cur < prop) cur = prop; }

// stuff cutline

int main() {
	int i, j, n, goods, a, t;
	vector<pii> st, fl;
	scanf("%d%d", &goods, &n);
	FOR (i, goods) {
		scanf("%d%d", &a, &t);
		(t == 1 ? st : fl).PB(MP(a, i + 1));
	}
	sort(ALL(st), greater<pii>());
	vector<vector<pii> > res;
	FOR (i, n)
		if (i < st.size())
			res.PB(vector<pii>(1, st[i]));
		else break;
	FOR (j, n - i)
		if (j < fl.size())
			res.PB(vector<pii>(1, fl[j]));
		else break;
	assert(res.size() == n);
	vector<pii>& tail = res.back();
	tail.insert(tail.end(), st.begin() + i, st.end());
	tail.insert(tail.end(), fl.begin() + j, fl.end());
	sort(ALL(tail));
	i64 doubleSum = st.size() < n ? 0 : tail.front().first;
	FORS (i, st)
		if (i < n - 1)
			doubleSum += res[i][0].first;
	doubleSum = -doubleSum;
	FORS (i, res)
		FORS (j, res[i])
			doubleSum += res[i][j].first * 2;
	printf("%I64d.%d", doubleSum / 2, (doubleSum % 2) * 5);
	FORS (i, res) {
		printf("\n%d", res[i].size());
		FORS (j, res[i])
			printf(" %d", res[i][j].second);
	}
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#ifndef _DEBUG
#define NDEBUG
#endif
#include <cstdio>
#include <cmath>
#include <cctype>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <utility>
#include <string>
#include <map>
#include <set>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <numeric>
#include <functional>
using namespace std;

#define C(_a) memset(_a, 0, sizeof(_a))
#define ALL(_obj) (_obj).begin(),(_obj).end()
#define FORB(_i, _a, _b) for((_i) = (_a); (_i) < (_b); ++(_i))
#define FOR(_i, _n) FORB(_i, 0, _n)
#define FORS(_i, _obj) FOR(_i, (_obj).size())
#define ADJ(_i, _v) for((_i) = kick[_v]; (_i) >= 0; (_i) = foll[_i])
#define MP make_pair
#define PB push_back

typedef long long i64;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<i64, int> pi64i;

template<typename T> inline void remin(T& cur, const T& prop) { if (cur > prop) cur = prop; }
template<typename T> inline void remax(T& cur, const T& prop) { if (cur < prop) cur = prop; }

// stuff cutline

int main() {
	int i, j, n, goods, a, t;
	vector<pii> st, fl;
	scanf("%d%d", &goods, &n);
	FOR (i, goods) {
		scanf("%d%d", &a, &t);
		(t == 1 ? st : fl).PB(MP(a, i + 1));
	}
	sort(ALL(st), greater<pii>());
	vector<vector<pii> > res;
	FOR (i, n)
		if (i < st.size())
			res.PB(vector<pii>(1, st[i]));
		else break;
	FOR (j, n - i)
		if (j < fl.size())
			res.PB(vector<pii>(1, fl[j]));
		else break;
	assert(res.size() == n);
	vector<pii>& tail = res.back();
	tail.insert(tail.end(), fl.begin() + j, fl.end());
	sort(ALL(tail));
	int doubleSum = st.size() < n ? 0 : tail.front().first;
	FORS (i, st)
		if (i < n - 1)
			doubleSum += res[i][0].first;
	doubleSum = -doubleSum;
	FORS (i, res)
		FORS (j, res[i])
			doubleSum += res[i][j].first * 2;
	printf("%.1lf", doubleSum / 2.0);
	FORS (i, res) {
		printf("\n%d", res[i].size());
		FORS (j, res[i])
			printf(" %d", res[i][j].second);
	}
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#ifndef _DEBUG
#define NDEBUG
#endif
#include <cstdio>
#include <cmath>
#include <cctype>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <utility>
#include <string>
#include <map>
#include <set>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <numeric>
#include <functional>
using namespace std;

#define C(_a) memset(_a, 0, sizeof(_a))
#define ALL(_obj) (_obj).begin(),(_obj).end()
#define FORB(_i, _a, _b) for((_i) = (_a); (_i) < (_b); ++(_i))
#define FOR(_i, _n) FORB(_i, 0, _n)
#define FORS(_i, _obj) FOR(_i, (_obj).size())
#define ADJ(_i, _v) for((_i) = kick[_v]; (_i) >= 0; (_i) = foll[_i])
#define MP make_pair
#define PB push_back

typedef long long i64;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<i64, int> pi64i;

template<typename T> inline void remin(T& cur, const T& prop) { if (cur > prop) cur = prop; }
template<typename T> inline void remax(T& cur, const T& prop) { if (cur < prop) cur = prop; }

// stuff cutline

int main() {
	int i, j, n, goods, a, t;
	vector<pii> st, fl;
	scanf("%d%d", &goods, &n);
	FOR (i, goods) {
		scanf("%d%d", &a, &t);
		(t == 1 ? st : fl).PB(MP(a, i + 1));
	}
	sort(ALL(st), greater<pii>());
	vector<vector<pii> > res;
	FOR (i, n)
		if (i < st.size())
			res.PB(vector<pii>(1, st[i]));
		else break;
	FOR (j, n - i)
		if (j < fl.size())
			res.PB(vector<pii>(1, fl[j]));
		else break;
	assert(res.size() == n);
	vector<pii>& tail = res.back();
	tail.insert(tail.end(), st.begin() + i, st.end());
	tail.insert(tail.end(), fl.begin() + j, fl.end());
	sort(ALL(tail));
	int doubleSum = st.size() < n ? 0 : tail.front().first;
	FORS (i, st)
		if (i < n - 1)
			doubleSum += res[i][0].first;
	doubleSum = -doubleSum;
	FORS (i, res)
		FORS (j, res[i])
			doubleSum += res[i][j].first * 2;
	printf("%.1lf", doubleSum / 2.0);
	FORS (i, res) {
		printf("\n%d", res[i].size());
		FORS (j, res[i])
			printf(" %d", res[i][j].second);
	}
	return 0;
}


#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
using namespace std;

#define mp make_pair
typedef pair<int, int> pii;
typedef vector<int> VI;

const int N = 1002;

vector<pii> a, b;
VI res[N];
int n, m;
double cost, discount;

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

    int c,t ;
    scanf("%d %d", &n, &m);
    for(int i = 1; i <= n; i++){
        scanf("%d %d", &c, &t);
        if (t == 1) a.push_back(mp(c, i));
        else b.push_back(mp(c, i));
        cost += c;
    }
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    n = a.size();
    int i, j;
    if (n < m){
        for(i = 0; i < n; i++) res[i+1].push_back(a[i].second), discount += (a[i].first+0.0)/2;
        for(i = 0; i+n+1 < m; i++) res[n+i+1].push_back(b[i].second);
        for(j = i; j < b.size(); j++) res[m].push_back(b[j].second);
    }
    else{
        for(i = n-1; i >= n-m; i--) res[i+1].push_back(a[i].second), discount += (a[i].first+0.0)/2;
        int x = min(a[0].first, b[0].first);
        discount += (-a[n-m].first+0.0)/2 + (x+0.0)/2;
        for(i = 0; i < b.size(); i++) res[1].push_back(b[i].second);
    }
    cost -= discount;
    printf("%.1lf\n", cost);
    for(int i = 1; i <= m; i++){
        printf("%d ", res[i].size());
        for(int j = 0; j < res[i].size(); j++) printf("%d ", res[i][j]);
        printf("\n");
    }

    return 0;
}


#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
using namespace std;

#define mp make_pair
typedef pair<int, int> pii;
typedef vector<int> VI;

const int N = 1002;

vector<pii> a, b;
VI res[N];
int n, m;
double cost, discount;

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

    int c,t ;
    scanf("%d %d", &n, &m);
    for(int i = 1; i <= n; i++){
        scanf("%d %d", &c, &t);
        if (t == 1) a.push_back(mp(c, i));
        else b.push_back(mp(c, i));
        cost += c;
    }
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    n = a.size();
    int i, j;
    if (n < m){
        for(i = 0; i < n; i++) res[i+1].push_back(a[i].second), discount += (a[i].first+0.0)/2;
        for(i = 0; i+n+1 < m; i++) res[n+i+1].push_back(b[i].second);
        for(j = i; j < b.size(); j++) res[m].push_back(b[j].second);
    }
    else{
        for(i = n-1; i >= n-m; i--) res[i+1].push_back(a[i].second), discount += (a[i].first+0.0)/2;
        b.push_back(mp(1000000000,-1));
        int x = min(a[0].first, b[0].first);
        discount += (-a[n-m].first+0.0)/2 + (x+0.0)/2;
        for(i = 0; i < b.size()-1; i++) res[1].push_back(b[i].second);
    }
    cost -= discount;
    printf("%.1lf\n", cost);
    for(int i = 1; i <= m; i++){
        printf("%d ", res[i].size());
        for(int j = 0; j < res[i].size(); j++) printf("%d ", res[i][j]);
        printf("\n");
    }

    return 0;
}


#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
using namespace std;

#define mp make_pair
typedef pair<int, int> pii;
typedef vector<int> VI;

const int N = 1002;

vector<pii> a, b;
VI res[N];
int n, m;
double cost, discount;

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

    int c,t ;
    scanf("%d %d", &n, &m);
    for(int i = 1; i <= n; i++){
        scanf("%d %d", &c, &t);
        if (t == 1) a.push_back(mp(c, i));
        else b.push_back(mp(c, i));
        cost += c;
    }
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    n = a.size();
    int i, j;
    if (n < m){
        for(i = 0; i < n; i++) res[i+1].push_back(a[i].second), discount += (a[i].first+0.0)/2;
        for(i = 0; i+n+1 < m; i++) res[n+i+1].push_back(b[i].second);
        for(j = i; j < b.size(); j++) res[m].push_back(b[j].second);
    }
    else{
        for(i = n-1; i >= 0; i--) res[i+1].push_back(a[i].second), discount += (a[i].first+0.0)/2;
        int x = min(a[0].first, b[0].first);
        discount += (-res[1][0]+0.0)/2 + (x+0.0)/2;
        for(i = 0; i < b.size(); i++) res[1].push_back(b[i].second);
        //if (b[0].first < a[0].first) discount += (-a[0].first+0.0)/2 + (b[0].first+0.0)/2;
    }
    cost = cost - discount;
    printf("%.1lf\n", cost);
    for(int i = 1; i <= m; i++){
        printf("%d ", res[i].size());
        for(int j = 0; j < res[i].size(); j++) printf("%d ", res[i][j]);
        printf("\n");
    }

    return 0;
}


#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
using namespace std;

#define mp make_pair
typedef pair<int, int> pii;
typedef vector<int> VI;

const int N = 1002;

vector<pii> a, b;
VI res[N];
int n, m;
double cost, discount;

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

    int c,t ;
    scanf("%d %d", &n, &m);
    for(int i = 1; i <= n; i++){
        scanf("%d %d", &c, &t);
        if (t == 1) a.push_back(mp(c, i));
        else b.push_back(mp(c, i));
        cost += c;
    }
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    n = a.size();
    int i, j;
    if (n < m){
        for(i = 0; i < n; i++) res[i+1].push_back(a[i].second), discount += (a[i].first+0.0)/2;
        for(i = 0; i+n+1 < m; i++) res[n+i+1].push_back(b[i].second);
        for(j = i; j < b.size(); j++) res[m].push_back(b[j].second);
    }
    else{
        for(i = n-1; i >= n-m; i--) res[m-n+i+1].push_back(a[i].second), discount += (a[i].first+0.0)/2;
        b.push_back(mp(1000000000,-1));
        int x = min(a[0].first, b[0].first);
        discount += (-a[n-m].first+0.0)/2 + (x+0.0)/2;
        for(i = 0; i < b.size()-1; i++) res[1].push_back(b[i].second);
        for(int i = n-m-1; i >= 0; i--) res[1].push_back(a[i].second);
    }
    cost -= discount;
    printf("%.1lf\n", cost);
    for(int i = 1; i <= m; i++){
        printf("%d ", res[i].size());
        for(int j = 0; j < res[i].size(); j++) printf("%d ", res[i][j]);
        printf("\n");
    }

    return 0;
}


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

const int inf = 2147483647;

vector < int > cost[2], ind[2];
vector < int > bag[1005], ostInd;
int costOfInd[1005], srt[1005], temp[1005];
bool isTab[1005];
int n, k, iGlob;
int ansZ, ansQ;

bool cmp (int d1, int d2) {
    return cost[iGlob][d1] > cost[iGlob][d2];
}

void countCost (int ind) {
    int i;

    int sum = 0, mn = inf;
    bool flag = false;
    for (i = 0;i < bag[ind].size();i++) {
        sum += costOfInd[bag[ind][i]];
        mn = min(mn, costOfInd[bag[ind][i]]);
        if (isTab[bag[ind][i]])
            flag = true;
    }

    if (!flag) {
        ansZ += sum;
        return ;
    }

    sum -= (mn + 1) / 2;
    ansZ += sum;
    if (mn % 2 == 1) {
        if (ansQ == 1)
            ansZ++;
        ansQ = (ansQ + 1) % 2;
    }
}

int main () {
    //freopen("input.txt", "rt", stdin);
    //freopen("output.txt", "wt", stdout);
    int i, j, v, curCost;

    scanf("%d%d", &n, &k);
    for (i = 0;i < n;i++) {
        scanf("%d%d", &curCost, &v);
        v--;
        costOfInd[i] = curCost;
        cost[v].push_back(curCost);
        ind[v].push_back(i);
        if (v == 0)
            isTab[i] = true;
    }

    for (i = 0;i < 2;i++) {
        iGlob = i;
        for (j = 0;j < cost[i].size();j++)
            srt[j] = j;
        sort(srt, srt + cost[i].size(), cmp);

        for (j = 0;j < cost[i].size();j++)
            temp[j] = cost[i][srt[j]];
        for (j = 0;j < cost[i].size();j++)
            cost[i][j] = temp[j];

        for (j = 0;j < cost[i].size();j++)
            temp[j] = ind[i][srt[j]];
        for (j = 0;j < cost[i].size();j++)
            ind[i][j] = temp[j];
    }

    int to = min((int) cost[0].size(), k);
    for (i = 0;i < to;i++) {
        bag[i].push_back(ind[0][i]);
    }

    if (cost[0].size() >= k) {
        for (i = k;i < cost[0].size();i++)
            bag[k - 1].push_back(ind[0][i]);
        for (i = 0;i < cost[1].size();i++)
            bag[k - 1].push_back(ind[1][i]);
    }else
    {
        to = min((int) cost[1].size(), k - (int) cost[0].size());
        for (i = 0;i < to;i++)
            bag[cost[0].size() + i].push_back(ind[1][i]);
        for (i = to;i < cost[1].size();i++)
            bag[k - 1].push_back(ind[1][i]);
    }

    ansZ = 0; ansQ = 0;
    for (i = 0;i < k;i++)
        countCost(i);

    printf("%d", ansZ);
    if (ansQ == 0)
        printf(".0");
    else
        printf(".5");
    for (i = 0;i < k;i++) {
        printf("\n%d", bag[i].size());
        for (j = 0;j < bag[i].size();j++)
            printf(" %d", bag[i][j] + 1);
    }
    return 0;
}


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

const int inf = 2147483647;

vector < int > cost[2], ind[2];
vector < int > bag[1005], ostInd;
int costOfInd[1005], srt[1005], temp[1005];
bool isTab[1005];
int n, k, iGlob;
__int64 ansZ, ansQ;

bool cmp (int d1, int d2) {
    return cost[iGlob][d1] > cost[iGlob][d2];
}

void countCost (int ind) {
    int i;

    __int64 sum = 0;
    int mn = inf;
    bool flag = false;
    for (i = 0;i < bag[ind].size();i++) {
        sum += costOfInd[bag[ind][i]];
        mn = min(mn, costOfInd[bag[ind][i]]);
        if (isTab[bag[ind][i]])
            flag = true;
    }

    if (!flag) {
        ansZ += sum;
        return ;
    }

    sum -= (mn + 1) / 2;
    ansZ += sum;
    if (mn % 2 == 1) {
        if (ansQ == 1)
            ansZ++;
        ansQ = (ansQ + 1) % 2;
    }
}

int main () {
    //freopen("input.txt", "rt", stdin);
    //freopen("output.txt", "wt", stdout);
    int i, j, v, curCost;

    scanf("%d%d", &n, &k);
    for (i = 0;i < n;i++) {
        scanf("%d%d", &curCost, &v);
        v--;
        costOfInd[i] = curCost;
        cost[v].push_back(curCost);
        ind[v].push_back(i);
        if (v == 0)
            isTab[i] = true;
    }

    for (i = 0;i < 2;i++) {
        iGlob = i;
        for (j = 0;j < cost[i].size();j++)
            srt[j] = j;
        sort(srt, srt + cost[i].size(), cmp);

        for (j = 0;j < cost[i].size();j++)
            temp[j] = cost[i][srt[j]];
        for (j = 0;j < cost[i].size();j++)
            cost[i][j] = temp[j];

        for (j = 0;j < cost[i].size();j++)
            temp[j] = ind[i][srt[j]];
        for (j = 0;j < cost[i].size();j++)
            ind[i][j] = temp[j];
    }

    int to = min((int) cost[0].size(), k);
    for (i = 0;i < to;i++) {
        bag[i].push_back(ind[0][i]);
    }

    if (cost[0].size() >= k) {
        for (i = k;i < cost[0].size();i++)
            bag[k - 1].push_back(ind[0][i]);
        for (i = 0;i < cost[1].size();i++)
            bag[k - 1].push_back(ind[1][i]);
    }else
    {
        to = min((int) cost[1].size(), k - (int) cost[0].size());
        for (i = 0;i < to;i++)
            bag[cost[0].size() + i].push_back(ind[1][i]);
        for (i = to;i < cost[1].size();i++)
            bag[k - 1].push_back(ind[1][i]);
    }

    ansZ = 0; ansQ = 0;
    for (i = 0;i < k;i++)
        countCost(i);

    printf("%I64d", ansZ);
    if (ansQ == 0)
        printf(".0");
    else
        printf(".5");
    for (i = 0;i < k;i++) {
        printf("\n%d", bag[i].size());
        for (j = 0;j < bag[i].size();j++)
            printf(" %d", bag[i][j] + 1);
    }
    return 0;
}


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

const int inf = 2147483647;

vector < int > cost[2], ind[2];
vector < int > bag[1005], ostInd;
int costOfInd[1005], srt[1005], temp[1005];
bool isTab[1005];
int n, k, iGlob;
int ansZ, ansQ;

bool cmp (int d1, int d2) {
    return cost[iGlob][d1] > cost[iGlob][d2];
}

void countCost (int ind) {
    int i;

    int sum = 0, mn = inf;
    bool flag = false;
    for (i = 0;i < bag[ind].size();i++) {
        sum += costOfInd[bag[ind][i]];
        mn = min(mn, costOfInd[bag[ind][i]]);
        if (isTab[bag[ind][i]])
            flag = true;
    }

    if (!flag) {
        ansZ += sum;
        return ;
    }

    sum -= (mn + 1) / 2;
    ansZ += sum;
    if (mn % 2 == 1) {
        if (ansQ == 1)
            ansZ++;
        ansQ = (ansQ + 1) % 2;
    }
}

int main () {
    //freopen("input.txt", "rt", stdin);
    //freopen("output.txt", "wt", stdout);
    int i, j, v, curCost;

    scanf("%d%d", &n, &k);
    for (i = 0;i < n;i++) {
        scanf("%d%d", &curCost, &v);
        v--;
        costOfInd[i] = curCost;
        cost[v].push_back(curCost);
        ind[v].push_back(i);
        if (v == 0)
            isTab[i] = true;
    }

    for (i = 0;i < 2;i++) {
        iGlob = i;
        for (j = 0;j < cost[i].size();j++)
            srt[j] = j;
        sort(srt, srt + cost[i].size(), cmp);

        for (j = 0;j < cost[i].size();j++)
            temp[j] = cost[i][srt[j]];
        for (j = 0;j < cost[i].size();j++)
            cost[i][j] = temp[j];

        for (j = 0;j < cost[i].size();j++)
            temp[j] = ind[i][srt[j]];
        for (j = 0;j < cost[i].size();j++)
            ind[i][j] = temp[j];
    }

    int to = min((int) cost[0].size(), k);
    for (i = 0;i < to;i++) {
        bag[i].push_back(ind[0][i]);
    }

    if (cost[0].size() >= k) {
        for (i = k;i < cost[0].size();i++)
            bag[k - 1].push_back(ind[0][i]);
        for (i = 0;i < cost[1].size();i++)
            bag[k - 1].push_back(ind[1][i]);
    }else
    {
        to = k - cost[0].size();
        for (i = 0;i < to;i++)
            bag[cost[0].size() + i].push_back(ind[1][i]);
        for (i = to;i < cost[1].size();i++)
            bag[k - 1].push_back(ind[1][i]);
    }

    ansZ = 0; ansQ = 0;
    for (i = 0;i < k;i++)
        countCost(i);

    printf("%d", ansZ);
    if (ansQ == 0)
        printf(".0");
    else
        printf(".5");
    for (i = 0;i < k;i++) {
        printf("\n%d", bag[i].size());
        for (j = 0;j < bag[i].size();j++)
            printf(" %d", bag[i][j] + 1);
    }
    return 0;
}


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

const int inf = 2147483647;

vector < int > cost[2], ind[2];
vector < int > bag[1005], ostInd;
int costOfInd[1005], srt[1005], temp[1005];
bool isTab[1005];
int n, k, iGlob;
__int64 ansZ, ansQ;

bool cmp (int d1, int d2) {
    return cost[iGlob][d1] > cost[iGlob][d2];
}

void countCost (int ind) {
    int i;

    __int64 sum = 0, mn = inf;
    bool flag = false;
    for (i = 0;i < bag[ind].size();i++) {
        sum += costOfInd[bag[ind][i]];
        mn = min(mn, costOfInd[bag[ind][i]]);
        if (isTab[bag[ind][i]])
            flag = true;
    }

    if (!flag) {
        ansZ += sum;
        return ;
    }

    sum -= (mn + 1) / 2;
    ansZ += sum;
    if (mn % 2 == 1) {
        if (ansQ == 1)
            ansZ++;
        ansQ = (ansQ + 1) % 2;
    }
}

int main () {
    //freopen("input.txt", "rt", stdin);
    //freopen("output.txt", "wt", stdout);
    int i, j, v, curCost;

    scanf("%d%d", &n, &k);
    for (i = 0;i < n;i++) {
        scanf("%d%d", &curCost, &v);
        v--;
        costOfInd[i] = curCost;
        cost[v].push_back(curCost);
        ind[v].push_back(i);
        if (v == 0)
            isTab[i] = true;
    }

    for (i = 0;i < 2;i++) {
        iGlob = i;
        for (j = 0;j < cost[i].size();j++)
            srt[j] = j;
        sort(srt, srt + cost[i].size(), cmp);

        for (j = 0;j < cost[i].size();j++)
            temp[j] = cost[i][srt[j]];
        for (j = 0;j < cost[i].size();j++)
            cost[i][j] = temp[j];

        for (j = 0;j < cost[i].size();j++)
            temp[j] = ind[i][srt[j]];
        for (j = 0;j < cost[i].size();j++)
            ind[i][j] = temp[j];
    }

    int to = min((int) cost[0].size(), k);
    for (i = 0;i < to;i++) {
        bag[i].push_back(ind[0][i]);
    }

    if (cost[0].size() >= k) {
        for (i = k;i < cost[0].size();i++)
            bag[k - 1].push_back(ind[0][i]);
        for (i = 0;i < cost[1].size();i++)
            bag[k - 1].push_back(ind[1][i]);
    }else
    {
        to = min((int) cost[1].size(), k - (int) cost[0].size());
        for (i = 0;i < to;i++)
            bag[cost[0].size() + i].push_back(ind[1][i]);
        for (i = to;i < cost[1].size();i++)
            bag[k - 1].push_back(ind[1][i]);
    }

    ansZ = 0; ansQ = 0;
    for (i = 0;i < k;i++)
        countCost(i);

    printf("%I64d", ansZ);
    if (ansQ == 0)
        printf(".0");
    else
        printf(".5");
    for (i = 0;i < k;i++) {
        printf("\n%d", bag[i].size());
        for (j = 0;j < bag[i].size();j++)
            printf(" %d", bag[i][j] + 1);
    }
    return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>
#include <cstring>
#include <queue>
#include <iomanip>
#pragma comment(linker, "/stack:50000000")

#define LIM 502

using namespace std;

int ps[1010], ts[1010];
vector<pair<int, int> > pi, di;
vector<int> bs[1010];

int main()
{
	int sm = 0;
	int n, k;
	cin >> n >> k;
	for (int i = 1; i <= n; i++)
	{
		cin >> ps[i] >> ts[i];
		sm += ps[i];
		if (ts[i] == 1)
			pi.push_back(make_pair(ps[i], i));
		else
			di.push_back(make_pair(ps[i], i));
	}
	sort(pi.begin(), pi.end());
	int bn = 1;
	int ovs = 0;
	for (int i = pi.size() - 1; i >= 0; i--)
	{
		if (bn <= k)
		{
			bs[bn].push_back(pi[i].second);
			ovs += pi[i].first;
			bn++;
		}
		else
		{
			bs[k].push_back(pi[i].second);
			ovs -= ps[bs[k][bs[k].size() - 2]];
			ovs += pi[i].first;
		}
	}
	int kk = 0;
	bool aa = false;
	if (bs[k].size() > 0)
	{
		aa = true;
		ovs -= ps[bs[k][bs[k].size() - 1]];
		kk = ps[bs[k][bs[k].size() - 1]];
	}
	int dn = 0;
	while (bn <= k)
	{
		bs[bn].push_back(di[dn].second);
		dn++;
		bn++;
	}
	while (dn < di.size())
	{
		bs[k].push_back(di[dn].second);
		if (di[dn].first < kk) kk = di[dn].first;
		dn++;
	}
	ovs += kk;
	double ans = double(sm) - double(ovs) / 2.0;
	cout << fixed << setprecision(1) << ans + 1e-5 << endl;
	for (int i = 1; i <= k; i++)
	{
		cout << bs[i].size();
		for (int j = 0; j < bs[i].size(); j++)
			cout << ' ' << bs[i][j];
		cout << endl;
	}
	return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>
#include <cstring>
#include <queue>
#include <iomanip>
#pragma comment(linker, "/stack:50000000")

#define LIM 502

using namespace std;

int ps[1010], ts[1010];
vector<pair<int, int> > pi, di;
vector<int> bs[1010];

int main()
{
	long long sm = 0;
	int n, k;
	cin >> n >> k;
	for (int i = 1; i <= n; i++)
	{
		cin >> ps[i] >> ts[i];
		sm += ps[i];
		if (ts[i] == 1)
			pi.push_back(make_pair(ps[i], i));
		else
			di.push_back(make_pair(ps[i], i));
	}
	sort(pi.begin(), pi.end());
	int bn = 1;
	long long ovs = 0;
	for (int i = pi.size() - 1; i >= 0; i--)
	{
		if (bn <= k)
		{
			bs[bn].push_back(pi[i].second);
			ovs += pi[i].first;
			bn++;
		}
		else
		{
			bs[k].push_back(pi[i].second);
			ovs -= ps[bs[k][bs[k].size() - 2]];
			ovs += pi[i].first;
		}
	}
	long long kk = 0;
	if (bs[k].size() > 0)
	{
		ovs -= ps[bs[k][bs[k].size() - 1]];
		kk = ps[bs[k][bs[k].size() - 1]];
	}
	int dn = 0;
	while (bn <= k)
	{
		bs[bn].push_back(di[dn].second);
		dn++;
		bn++;
	}
	while (dn < di.size())
	{
		bs[k].push_back(di[dn].second);
		if (di[dn].first < kk) kk = di[dn].first;
		dn++;
	}
	ovs += kk;
	int ans;
	if (ovs % 2 == 0)
	{
		ans = sm - ovs / 2;
		cout << ans << ".0" << endl;
	}
	else
	{
		ans = sm - (ovs + 1) / 2;
		cout << ans << ".5" << endl;
	}
	for (int i = 1; i <= k; i++)
	{
		cout << bs[i].size();
		for (int j = 0; j < bs[i].size(); j++)
			cout << ' ' << bs[i][j];
		cout << endl;
	}
	return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>
#include <cstring>
#include <queue>
#include <iomanip>
#pragma comment(linker, "/stack:50000000")

#define LIM 502

using namespace std;

int ps[1010], ts[1010];
vector<pair<int, int> > pi, di;
vector<int> bs[1010];

int main()
{
	long long sm = 0;
	int n, k;
	cin >> n >> k;
	for (int i = 1; i <= n; i++)
	{
		cin >> ps[i] >> ts[i];
		sm += ps[i];
		if (ts[i] == 1)
			pi.push_back(make_pair(ps[i], i));
		else
			di.push_back(make_pair(ps[i], i));
	}
	sort(pi.begin(), pi.end());
	int bn = 1;
	long long ovs = 0;
	for (int i = pi.size() - 1; i >= 0; i--)
	{
		if (bn <= k)
		{
			bs[bn].push_back(pi[i].second);
			ovs += pi[i].first;
			bn++;
		}
		else
		{
			bs[k].push_back(pi[i].second);
			ovs -= ps[bs[k][bs[k].size() - 2]];
			ovs += pi[i].first;
		}
	}
	long long kk = 0;
	if (bs[k].size() > 0)
	{
		ovs -= ps[bs[k][bs[k].size() - 1]];
		kk = ps[bs[k][bs[k].size() - 1]];
	}
	int dn = 0;
	while (bn <= k)
	{
		bs[bn].push_back(di[dn].second);
		dn++;
		bn++;
	}
	while (dn < di.size())
	{
		bs[k].push_back(di[dn].second);
		if (di[dn].first < kk) kk = di[dn].first;
		dn++;
	}
	ovs += kk;
	long long ans;
	if (ovs % 2 == 0)
	{
		ans = sm - ovs / 2;
		cout << ans << ".0" << endl;
	}
	else
	{
		ans = sm - (ovs + 1) / 2;
		cout << ans << ".5" << endl;
	}
	for (int i = 1; i <= k; i++)
	{
		cout << bs[i].size();
		for (int j = 0; j < bs[i].size(); j++)
			cout << ' ' << bs[i][j];
		cout << endl;
	}
	return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>
#include <cstring>
#include <queue>
#include <iomanip>
#pragma comment(linker, "/stack:50000000")

#define LIM 502

using namespace std;

int ps[1010], ts[1010];
vector<pair<int, int> > pi, di;
vector<int> bs[1010];

int main()
{
	long long sm = 0;
	int n, k;
	cin >> n >> k;
	for (int i = 1; i <= n; i++)
	{
		cin >> ps[i] >> ts[i];
		sm += ps[i];
		if (ts[i] == 1)
			pi.push_back(make_pair(ps[i], i));
		else
			di.push_back(make_pair(ps[i], i));
	}
	sort(pi.begin(), pi.end());
	int bn = 1;
	long long ovs = 0;
	for (int i = pi.size() - 1; i >= 0; i--)
	{
		if (bn <= k)
		{
			bs[bn].push_back(pi[i].second);
			ovs += pi[i].first;
			bn++;
		}
		else
		{
			bs[k].push_back(pi[i].second);
			ovs -= ps[bs[k][bs[k].size() - 2]];
			ovs += pi[i].first;
		}
	}
	long long kk = 0;
	if (bs[k].size() > 0)
	{
		ovs -= ps[bs[k][bs[k].size() - 1]];
		kk = ps[bs[k][bs[k].size() - 1]];
	}
	int dn = 0;
	while (bn <= k)
	{
		bs[bn].push_back(di[dn].second);
		dn++;
		bn++;
	}
	while (dn < di.size())
	{
		bs[k].push_back(di[dn].second);
		if (di[dn].first < kk) kk = di[dn].first;
		dn++;
	}
	ovs += kk;
	int ans;
	if (ovs % 2 == 0)
	{
		ans = sm - ovs / 2;
		cout << ans << endl;
	}
	else
	{
		ans = sm - (ovs + 1) / 2;
		cout << ans << ".5" << endl;
	}
	for (int i = 1; i <= k; i++)
	{
		cout << bs[i].size();
		for (int j = 0; j < bs[i].size(); j++)
			cout << ' ' << bs[i][j];
		cout << endl;
	}
	return 0;
}


#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <math.h>
#include <string.h>
#include <algorithm>
#include <cstring>
#include <vector>
#include <map>
#include <ctime>

using namespace std;

typedef long long i64;
typedef pair<int,int> pii;

bool comp(pii a,pii b)
{
	if (a.first<b.first) return false;
	else return true;
}

int main()
{
	int n,k;
	cin >> n >> k;
	int tmp,cl;
	vector<pair<int,int>> a1;
	vector<pair<int,int>> a2;
	double totalcost=0;
	for (int i=0;i<n;i++)
	{
		scanf("%d%d",&tmp,&cl);
		totalcost+=tmp;
		if (cl==1)
			a1.push_back(make_pair(tmp,i+1));
		else
			a2.push_back(make_pair(tmp,i+1));
	}
	sort(a1.begin(),a1.end(),comp);
	sort(a2.begin(),a2.end(),comp);
	vector<vector<int>> card(k);
	for (int i=0;i<a1.size() && i<k;i++)
	{
		totalcost-=a1[i].first*0.5;
		card[i].push_back(a1[i].second);
	}
	if (a1.size()<k)
	{
		for (int i=a1.size();i<k;i++)
			card[i].push_back(a2[i-a1.size()].second);
		for (int i=k-a1.size();i<a2.size();i++)
			card[k-1].push_back(a2[i].second);
	}
	else
	{
		for (int i=k;i<a1.size();i++)
			card[k-1].push_back(a1[i].second);
		for (int i=0;i<a2.size();i++)
			card[k-1].push_back(a2[i].second);
		totalcost+=a1[k-1].first*0.5-min(a1[a1.size()-1].first,a2[a2.size()-1].first)*0.5;
	}
	printf("%.1f",totalcost);
	for (int i=0;i<k;i++)
	{
		printf("\n%d ",card[i].size());
		for (int j=0;j<card[i].size();j++)
			printf("%d ",card[i][j]);

	}
	cout << endl;
	return 0;
}


#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <math.h>
#include <string.h>
#include <algorithm>
#include <cstring>
#include <vector>
#include <map>
#include <ctime>

using namespace std;

typedef long long i64;
typedef pair<int,int> pii;

bool comp(pii a,pii b)
{
	if (a.first<b.first) return false;
	else return true;
}

int main()
{
	int n,k;
	cin >> n >> k;
	int tmp,cl;
	vector<pair<int,int>> a1;
	vector<pair<int,int>> a2;
	double totalcost=0;
	for (int i=0;i<n;i++)
	{
		scanf("%d%d",&tmp,&cl);
		totalcost+=tmp;
		if (cl==1)
			a1.push_back(make_pair(tmp,i+1));
		else
			a2.push_back(make_pair(tmp,i+1));
	}
	sort(a1.begin(),a1.end(),comp);
	sort(a2.begin(),a2.end(),comp);
	vector<vector<int>> card(k);
	for (int i=0;i<a1.size() && i<k;i++)
	{
		totalcost-=a1[i].first*0.5;
		card[i].push_back(a1[i].second);
	}
	if (a1.size()<k)
	{
		for (int i=a1.size();i<k;i++)
			card[i].push_back(a2[i-a1.size()].second);
		for (int i=k-a1.size();i<a2.size();i++)
			card[k-1].push_back(a2[i].second);
	}
	else
	{
		for (int i=k;i<a1.size();i++)
			card[k-1].push_back(a1[i].second);
		for (int i=0;i<a2.size();i++)
			card[k-1].push_back(a2[i].second);
		if (a2.size())
			totalcost+=a1[k-1].first*0.5-min(a1[a1.size()-1].first,a2[a2.size()-1].first)*0.5;
	}
	printf("%.1f",totalcost);
	for (int i=0;i<k;i++)
	{
		printf("\n%d ",card[i].size());
		for (int j=0;j<card[i].size();j++)
			printf("%d ",card[i][j]);

	}
	cout << endl;
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip>
#include <sstream>
#include <utility>
#include <string>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <bitset>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cmath>
#include <ctime>
#include <assert.h>
#include <string.h>
#include <limits>
using namespace std;

#define INF 100000000
#define PI 3.1415926535897932384626433832795
#define PI_HALF 1.570796327
#define EPS 1e-9

typedef unsigned int UI;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair< int, int > PII;
typedef pair< LL, LL > PLL;
typedef vector< int > VI;
typedef vector< LL > VLL;
typedef vector< string > VS;
typedef vector< PII > VPII;
typedef vector< PLL > VPLL;

#define X first
#define Y second
#define PB push_back
#define MP make_pair
#define SZ(c) (int)(c).size()
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort( ALL( c ) )
#define SORT_(c,f) sort( ALL( c ), f )
#define FILL(x,v) memset( x, v, sizeof( x ) );

#define REP(i,n) for ( int i = 0, max_ = (n); i < max_; ++i )
#define REPD(i,n) for ( int i = (n) - 1; i >= 0; --i )
#define FOR(i,a,b) for ( int i = (a), max_ = (b); i < max_; ++i )
#define FORD(i,a,b) for ( int i = (a) - 1, min_ = (b); i >= min_; --i )

int ToInt ( string & s, int len ) { int r = 0; REP(i,len) { r *= 10; r += s[i] - '0'; } return r; }
int GCD ( int a, int b ) { return b != 0 ? GCD(b, a % b) : a; }
int LCM ( int a, int b ) { return a*(b / GCD(a,b)); }
LL Pow ( LL n, LL e ) { if ( e == 0 ) return 1; if ( e == 1 ) return n; else if ( e & 1 ) { LL t = Pow(n,e/2); return n*t*t; } else { LL t = Pow(n,e/2); return t*t; } }

int main ()
{
    VPII v1, v2;
    int N, K, a, b;
    scanf( "%d %d", &N, &K );
    REP(i,N)
    {
        scanf( "%d %d", &a, &b );
        if ( b == 1 ) v1.PB( MP( a, i + 1 ) );
        else v2.PB( MP( a, i + 1 ) );
    }
    SORT_(v1,greater<PII>());

    VI c[ 1001 ];
    double price = 0.0;
    int u = min( K - 1, SZ(v1) );
    REP(i,u)
    {
        c[ i ].PB( v1[ i ].Y );
        price += 0.5 * v1[ i ].X;
    }

    bool rem = u < SZ(v1);
    if ( rem )
    {
        int min = numeric_limits< int >::max();
        FOR(i,u,SZ(v1))
        {
            price += v1[ i ].X;
            min = std::min( min, v1[ i ].X );
            c[ K - 1 ].PB( v1[ i ].Y );
        }
        REP(i,SZ(v2))
        {
            price += v2[ i ].X;
            min = std::min( min, v2[ i ].X );
            c[ K - 1 ].PB( v2[ i ].Y );
        }
        price -= 0.5 * min;
    }
    else
    {
        int start = u;
        REP(i,SZ(v2))
        {
            price += v2[ i ].X;
            c[ start++ ].PB( v2[ i ].Y );
            if ( start == K ) start = K-1;
        }
    }

    printf( "%lf\n", price );
    REP(i,K)
    {
        printf( "%d", SZ(c[i]) );
        REP(j,SZ(c[i]))
            printf( " %d", c[i][j] );
        printf( "\n" );
    }

    return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip>
#include <sstream>
#include <utility>
#include <string>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <bitset>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cmath>
#include <ctime>
#include <assert.h>
#include <string.h>
#include <limits>
using namespace std;

#define INF 100000000
#define PI 3.1415926535897932384626433832795
#define PI_HALF 1.570796327
#define EPS 1e-9

typedef unsigned int UI;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair< int, int > PII;
typedef pair< LL, LL > PLL;
typedef vector< int > VI;
typedef vector< LL > VLL;
typedef vector< string > VS;
typedef vector< PII > VPII;
typedef vector< PLL > VPLL;

#define X first
#define Y second
#define PB push_back
#define MP make_pair
#define SZ(c) (int)(c).size()
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort( ALL( c ) )
#define SORT_(c,f) sort( ALL( c ), f )
#define FILL(x,v) memset( x, v, sizeof( x ) );

#define REP(i,n) for ( int i = 0, max_ = (n); i < max_; ++i )
#define REPD(i,n) for ( int i = (n) - 1; i >= 0; --i )
#define FOR(i,a,b) for ( int i = (a), max_ = (b); i < max_; ++i )
#define FORD(i,a,b) for ( int i = (a) - 1, min_ = (b); i >= min_; --i )

int ToInt ( string & s, int len ) { int r = 0; REP(i,len) { r *= 10; r += s[i] - '0'; } return r; }
int GCD ( int a, int b ) { return b != 0 ? GCD(b, a % b) : a; }
int LCM ( int a, int b ) { return a*(b / GCD(a,b)); }
LL Pow ( LL n, LL e ) { if ( e == 0 ) return 1; if ( e == 1 ) return n; else if ( e & 1 ) { LL t = Pow(n,e/2); return n*t*t; } else { LL t = Pow(n,e/2); return t*t; } }

int main ()
{
    VPII v1, v2;
    int N, K, a, b;
    scanf( "%d %d", &N, &K );
    REP(i,N)
    {
        scanf( "%d %d", &a, &b );
        if ( b == 1 ) v1.PB( MP( a, i + 1 ) );
        else v2.PB( MP( a, i + 1 ) );
    }
    SORT_(v1,greater<PII>());

    VI c[ 1001 ];
    double price = 0.0;
    int u = min( K - 1, SZ(v1) );
    REP(i,u)
    {
        c[ i ].PB( v1[ i ].Y );
        price += 0.5 * v1[ i ].X;
    }

    bool rem = u < SZ(v1);
    if ( rem )
    {
        int min = numeric_limits< int >::max();
        FOR(i,u,SZ(v1))
        {
            price += v1[ i ].X;
            min = std::min( min, v1[ i ].X );
            c[ K - 1 ].PB( v1[ i ].Y );
        }
        REP(i,SZ(v2))
        {
            price += v2[ i ].X;
            min = std::min( min, v2[ i ].X );
            c[ K - 1 ].PB( v2[ i ].Y );
        }
        price -= 0.5 * min;
    }
    else
    {
        int start = u;
        REP(i,SZ(v2))
        {
            price += v2[ i ].X;
            c[ start++ ].PB( v2[ i ].Y );
            if ( start == K ) start = K-1;
        }
    }

    printf( "%.01lf\n", price );
    REP(i,K)
    {
        printf( "%d", SZ(c[i]) );
        REP(j,SZ(c[i]))
            printf( " %d", c[i][j] );
        printf( "\n" );
    }

    return 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <map>
#include <set>
using namespace std;
struct my
{
    int tp,n,c;
    bool operator<(my &d)
    {
        if (tp==d.tp) return c>d.c;
        else return tp<d.tp;
    };
};
int main()
{
   // freopen("inp.txt","rt",stdin);
    int n,m,i,j,k,x,y;
    scanf("%d%d",&n,&m);
    vector<my> v(n);
    for (i=0;i<n;++i)
    {
        scanf("%d%d",&v[i].c,&v[i].tp);
        v[i].n=i;
    }
    sort(v.begin(),v.end());
    vector<vector<int> > a(m);
    double s=0;
    k=0;
    for (i=0;i<n;++i)
    {
        if (k==m)
        {
            a[m-1].push_back(i);
        }
        else
        {
            a[k].push_back(i);
            ++k;
        }
    }
    for (i=0;i<m;++i)
    {
        int fl=0;
        double mn=1000000009;
        double s1=0;
        for(j=0;j<a[i].size();++j)
        {
            if (v[a[i][j]].tp==1) fl=1;
            mn=min(mn,(double)v[a[i][j]].c);
            s1+=v[a[i][j]].c;
        }
        if (fl)
            s+=s1-mn+mn*0.5;
        else
            s+=s1;
    }
    printf("%0.1lf\n",s);
    for (i=0;i<m;i++)
    {
        printf("%d ",a[i].size());
        for (j=0;j<a[i].size();++j)
            printf("%d ",v[a[i][j]].n+1);
        printf("\n");
    }
}


#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <map>
#include <set>
using namespace std;
struct my
{
    int tp,n,c;
    bool operator<(my &d)
    {
        if (tp==d.tp) return c>d.c;
        else return tp<d.tp;
    };
};
int main()
{
   // freopen("inp.txt","rt",stdin);
    int n,m,i,j,k,x,y;
    scanf("%d%d",&n,&m);
    vector<my> v(n);
    for (i=0;i<n;++i)
    {
        scanf("%d%d",&v[i].c,&v[i].tp);
        v[i].n=i;
    }
    sort(v.begin(),v.end());
    vector<vector<int> > a(m);
    double s=0;
    k=0;
    for (i=0;i<n;++i)
    {
        if (k==m)
        {
            a[m-1].push_back(i);
        }
        else
        {
            a[k].push_back(i);
            ++k;
        }
    }
    for (i=0;i<m;++i)
    {
        int fl=0;
        int mn=1000000009;
        double s1=0;
        for(j=0;j<a[i].size();++j)
        {
            if (v[a[i][j]].tp==1) fl=1;
            mn=min(mn,v[a[i][j]].c);
            s1+=v[a[i][j]].c;
        }
        if (fl)
            s+=s1-mn+mn*0.5;
        else
            s+=s1;
    }
    printf("%0.1lf\n",s);
    for (i=0;i<m;i++)
    {
        printf("%d ",a[i].size());
        for (j=0;j<a[i].size();++j)
            printf("%d ",a[i][j]+1);
        printf("\n");
    }
}


#include <algorithm>
#include <iostream>
#include <string.h>
#include <string>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <map>
#include <set>

using namespace std;

const int MAXN = 2010;

struct Pen{
    int p;
    int id;
}pen[MAXN];
struct Sto{
    int p;
    int id;
}sto[MAXN];

bool comp1(Pen p1, Pen p2){
    return p1.p < p2.p;
}
bool comp2(Sto s1, Sto s2){
    return s1.p < s2.p;
}

vector<int>v[MAXN];

int in[MAXN];
bool has[MAXN];

int main(){
    int n, k;
    while (scanf("%d%d", &n, &k) != EOF){
        for (int i = 0; i <= k; i++){
            v[i].clear();
        }
        int p, id, pnum = 0, snum = 0;
        memset(has, false, sizeof(has));
        for (int i = 0; i < n; i++){
            scanf("%d%d", &in[i], &id);
            if (id == 1){
                sto[snum].p = in[i];
                sto[snum++].id = i + 1;
            }
            if (id == 2){
                pen[pnum].p = in[i];
                pen[pnum++].id = i + 1;
            }
        }
        sort(pen, pen + pnum, comp1);
        sort(sto, sto + snum, comp2);
        int i;
        for (i = 0; i < k && i < snum; i++){
            v[i].push_back(sto[i].id);
            has[i] = true;
        }
        if (i < snum){
            for (; i < snum; i++){
                v[0].push_back(sto[i].id);
            }
            for (int j = 0; j < pnum; j++){
                v[0].push_back(pen[j].id);
            }
        }else{
            int j;
            for (j = 0; i < k && j < pnum; i++, j++){
                v[i].push_back(pen[j].id);
            }
            for (; j < pnum; j++){
                v[k - 1].push_back(pen[j].id);
            }
        }
        double ans = 0;
        for (int i = 0; i < k; i++){
            double sum = 0;
            int MIN = 1000000010;
            int size = v[i].size();
            for (int j= 0; j < size; j++){
                sum += in[v[i][j] - 1];
                if (MIN > in[v[i][j] - 1]){
                    MIN = in[v[i][j] - 1];
                }
            }
            if (has[i]){
                sum = sum - MIN * 0.5;
            }
            ans += sum;
        }
        printf("%.1lf\n", ans);
        for (int i = 0; i < k; i++){
            int size = v[i].size();
            cout << size << " ";
            for (int j = 0; j < size - 1; j++){
                cout << v[i][j] << " ";
            }
            cout << v[i][size - 1] << endl;
        }
    }
   return 0;
}