One day Polycarpus stopped by a supermarket on his way home. It turns out that the supermarket is having a special offer for stools. The offer is as follows: if a customer's shopping cart contains at least one stool, the customer gets a 50% discount on the cheapest item in the cart (that is, it becomes two times cheaper). If there are several items with the same minimum price, the discount is available for only one of them!Polycarpus has k carts, and he wants to buy up all stools and pencils from the supermarket. Help him distribute the stools and the pencils among the shopping carts, so that the items' total price (including the discounts) is the least possible.Polycarpus must use all k carts to purchase the items, no shopping cart can remain empty. Each shopping cart can contain an arbitrary number of stools and/or pencils.

The first input line contains two integers n and k (1 ≤ k ≤ n ≤ 103) — the number of items in the supermarket and the number of carts, correspondingly. Next n lines describe the items as "ci ti" (without the quotes), where ci (1 ≤ ci ≤ 109) is an integer denoting the price of the i-th item, ti (1 ≤ ti ≤ 2) is an integer representing the type of item i (1 for a stool and 2 for a pencil). The numbers in the lines are separated by single spaces.

In the first line print a single real number with exactly one  decimal place — the minimum total price of the items, including the discounts. In the following k lines print the descriptions of the items in the carts. In the i-th line print the description of the i-th cart as "t b1 b2 ... bt" (without the quotes), where t is the number of items in the i-th cart, and the sequence b1, b2, ..., bt (1 ≤ bj ≤ n) gives the indices of items to put in this cart in the optimal distribution. All indices of items in all carts should be pairwise different, each item must belong to exactly one cart. You can print the items in carts and the carts themselves in any order. The items are numbered from 1 to n in the order in which they are specified in the input. If there are multiple optimal distributions, you are allowed to print any of them.

NoteIn the first sample case the first cart should contain the 1st and 2nd items, and the second cart should contain the 3rd item. This way each cart has a stool and each cart has a 50% discount for the cheapest item. The total price of all items will be: 2·0.5 + (3 + 3·0.5) = 1 + 4.5 = 5.5.

<?php
error_reporting(0);

class Item{
	private $index;
	private $type;
	private $price;

	public function __construct($index, $type, $price) {
		$this->index = $index;
		$this->type = $type;
		$this->price = $price;
	}

	public function getIndex() {
		return $this->index;
	}

	public function getPrice() {
		return $this->price;
	}

	public function getType() {
		return $this->type;
	}

	static function compareItem(Item $a_item, Item $b_item) {
		$a_t = $a_item->getType();
		$b_t = $b_item->getType();
		$a_p = $a_item->getPrice();
		$b_p = $b_item->getPrice();

		if ($a_t < $b_t) return -1;
		elseif ($a_t > $b_t) return 1;
		elseif ($a_t === $b_t) {
			if ($a_p > $b_p) return -1;
			elseif ($a_p === $b_p) return 0;
			elseif ($a_p < $b_p) return 1;
		}
	}
}
/* 50ms 30ms faster than class static func
function compare(Item $a_item , Item $b_item){
	//$a_t = $a->getType();
	//$b_t = $b->getType();
	//$a_p = $a->getPrice();
	//$b_p = $b->getPrice();
	$a_t = $a_item->getType();
	$b_t = $b_item->getType();
	$a_p = $a_item->getPrice();
	$b_p = $b_item->getPrice();

	if ($a_t < $b_t) {
		return -1;
	} elseif ($a_t > $b_t) {
		return 1;
	//} elseif ($a_t = $b_t) {
	} elseif ($a_t === $b_t) {
		if ($a_p > $b_p) {
			//return 1;
			return -1;
		//} elseif ($a_p = $b_p) {
		} elseif ($a_p === $b_p) {
			return 0;
		} elseif ($a_p < $b_p) {
			//return -1;
			return 1;
		}
	}
}
*/
function solve(){
	$Scanner = new Scanner("php://stdin");
	//$Scanner = new Scanner("input.txt");

	$inp_N = (int)$Scanner->Scan();
	$inp_K = (int)$Scanner->Scan();

	for ($i = 0; $i < $inp_N; $i++) {
		$PRICE = $Scanner->Scan();
		$TYPE = (int)$Scanner->Scan();
		$ITEMS[] = new Item($i + 1, $TYPE, $PRICE);
	}

	usort($ITEMS, array("Item", "compareItem"));
	//usort($ITEMS, "compare");
	for ($i = 0; $i < $inp_N; $i++) {
		if ($i < $inp_K - 1) {
			//$KART[$i] = $ITEMS[$i]->getIndex();
			$KART[$i][] = $ITEMS[$i]->getIndex();
		} elseif ($i >= $inp_K - 1) {
			$KART[$inp_K - 1][] = $ITEMS[$i]->getIndex();
		}
	}

	for ($i = 0; $i < $inp_N; $i++) {
		$type = $ITEMS[$i]->getType();
		if ($i < $inp_K - 1 && $type === 1) {
			$sum += $ITEMS[$i]->getPrice() / 2;
		} elseif ($i >= $inp_K - 1 || $type !== 1) {
			$sum += $ITEMS[$i]->getPrice();
		}
	}

	//$min = 1E9 + 1;
	if ($ITEMS[$inp_K - 1]->getType() === 1) {
		$min = 1E9 + 1;
		for ($i = $inp_K - 1; $i < $inp_N; $i++) {
			$temp = $ITEMS[$i]->getPrice();
			$min = min($temp, $min);
		}
	}
	$sum -= $min / 2;

	printf("%.1f", $sum);
	print("\n");
	for ($i = 0; $i < $inp_K; $i++) {
		$count = count($KART[$i]);
		//print($sum);
		print($count);
		print(" ");
		$cou = 0;
		$c = 0;
		foreach ($KART[$i] as $as_i) {
			if ($i !== $inp_K - 1) {
				print($as_i);
				$cou++;
				//if ($cou != $count - 1) {
				if ($cou != $count) {
					print(" ");
				} else {
					print("\n");
				}
			} else {
				print($as_i);
				$c++;
				//if ($c != $count - 1) {
				if ($c != $count) {
					print(" ");
				}
			}
		}
	}
	$Scanner->close();
}

ob_end_clean();
solve();

//error_reporting(0);
//$Scanner = new Scanner("php://stdin");
class Scanner{
	private $Stream;
	private $Scanners = array();
	private $Id = 0;

	public function __construct($opend){
		if((!is_file($opend) && !is_link($opend)) && $opend !== "php://stdin"){
  			print("file or link or ''php://stdin' err");
  			exit;
		}

		$this->Stream = fopen($opend, 'r');
		$contents = stream_get_contents($this->Stream);

		//err $c_row = array("\n", "\r", "\r\n");
		$c_row = array("\r\n", "\r", "\n");
		$contents = str_replace($c_row, " ", $contents);
		$this->Scanners = explode(" ", $contents);
	}

	function Scan(){
		$x = $this->Id;
		$sc = $this->Scanners[$x];
		$this->Id = ++$x;
		return $sc;
	}

	function close(){
		fclose($this->Stream);
	}
}

/*
====begin=====

//input    $inp_ or upper
//block    $temp_
//two block$ttemp_
//as 	   $as_
//instance $(Upper)
//ref      $ref
//class menba $^Upper

====end=======

===== class begin =====

//error_reporting(0);
//$Scanner = new Scanner("php://stdin");
//ref "#109_div2_B_1230942 laurenceHR"
class LineScanner{
	private $Stream;
	private $Scanners = array();
	private $LineIds_Of_ScanIds= array();
	private $LinesScanners = array();
	private $LastScanIds_Of_LineIds = array();
	private $Scan_number = 0;
	private $Scanline_number = 0;

	public function __construct($opend){
		if((!is_file($opend) && !is_link($opend)) && $opend !== "php://stdin"){
  			print("file or link err");
  			exit;
		}

		$this->Stream = fopen($opend, 'r');
		$contents = stream_get_contents($this->Stream);

		$temp_lines = explode("\n", $contents);
		$temp_linescanners = array();
		$temp_x = 0;
		$temp_y = 0;
		//--attention for initting of array--(these is not needed but for easily reading)//
		$ttemp_scanners = array();
		//$del = Array("\n","\r","\n\r");
		foreach ($temp_lines as $as_line) {
			if (strlen($as_line) === 0) {
				print("input err");
			}

			//$as_line = str_replace($del,'',$as_line);
			$temp_linescanners[] = $as_line;
			$ttemp_line_scanners = explode(" ", $as_line);
			//$ttemp_scanners = array();
			foreach ($ttemp_line_scanners as $as_sc) {
				$ttemp_scanners[] = $as_sc;
				$this->LineIds_Of_ScanIds[$temp_x] = $temp_y;
				$temp_x++;
			}
			$this->LastScanIds_Of_LineIds[$temp_y] = $temp_x - 1;
			$temp_y++;
		}
		$this->Scanners = $ttemp_scanners;
		$this->LinesScanners = $temp_linescanners;
	}

	function Scan(){
		$x = $this->Scan_number;
		$y = $this->Scanline_number;
		if ($this->LineIds_Of_ScanIds[$x] === false || $this->LastScanIds_Of_LineIds[$y] === false) {
			print("scan err");
		}

		$sc = $this->Scanners[$x];
		//--attention for ++$x//
		//$this->Scan_number = $x++;
		$this->Scan_number = ++$x;
		$this->Scanline_number = $this->LineIds_Of_ScanIds[$x];
		return $sc;
	}

	function LineScan(){
		$x = $this->Scan_number;
		$y = $this->Scanline_number;
		if ($this->LineIds_Of_ScanIds[$x] === false || $this->LastScanIds_Of_LineIds[$y] === false) {
			print("linescan err");
		}

		$lsc = $this->LinesScanners[$y];
		$this->Scan_number = $this->LastScanIds_Of_LineIds[$y] + 1;
		$this->Scanline_number = $y + 1;
		return $lsc;
	}

	function close(){
		fclose($this->Stream);
	}
}

class Token{
	private $token;
	private $tok;

	public function __construct($str_line, $tok) {
		$this->tok = $tok;
		$this->token = strtok($str_line, $this->tok);
	}

	public function nextToken() {
		$thisToken = $this->token;
		$this->token = strtok($this->tok);
		return $thisToken;
	}

	public function nextFloat() {
		return (float)$this->nextToken();
	}

  	public function nextInt() {
		return (int)$this->nextToken();
	}

	public function nextIntArray() {
		$temp_arr = array();
		$flag = -1;
		while ($flag !== 1) {
			$thisToken = $this->nextToken();
			if ($thisToken !== false) {
				$temp_arr[] = $thisToken;
			} else {
				$flag = 1;
			}
		}
		return $temp_arr;
	}

	public function nnextIntArray($num) {
		$temp_arr = array();
		for ($i = 0; $i < $num; $i++) {
			$temp_arr[] = (int)$this->token;
		}
		return $temp_arr;
	}
}
===== class end ======

=== function begin ===

function get_line() {
        $stdin = fopen("php://stdin", "r");
        $line = rtrim($stdin, "\n");
        fclose($stdin);
        return $line;
}

function num_printf($i){
	if (is_float($i)) {
		printf("%.0f", $i);
	}
	if (is_int($i)) {
		printf("%d", $i);
	}
}

function array_printf(array $array) {
		$message = "";
		foreach ($array as $value) {
			$message .= "$value" . " ";
		}
		$message = rtrim($message);
		printf('%s', $message);
}

== function end ======
*/

?>

<?php
//error_reporting(0);

class Item{
	private $index;
	private $type;
	private $price;

	public function __construct($index, $type, $price) {
		$this->index = $index;
		$this->type = $type;
		$this->price = $price;
	}

	public function getIndex() {
		return $this->index;
	}

	public function getPrice() {
		return $this->price;
	}

	public function getType() {
		return $this->type;
	}

/* static → private?
    static function cmp_obj($a, $b) {
        $a_t = $a->getType();
        $b_t = $b->getType();
        $a_p = $a->getType();
        $b_p = $b->getType();

        if ($a_t < $b_t) {
            return 1;
        } elseif ($a_t = $b_t) {
			if ($a_p > $b_p) {
				return 1;
			} elseif ($a_p = $b_p) {
				return 0;
			} elseif ($a_p < $b_p) {
				return -1;
			}
		}
	}
*/
}

function compare(Item $a_item , Item $b_item){
	//$a_t = $a->getType();
	//$b_t = $b->getType();
	//$a_p = $a->getPrice();
	//$b_p = $b->getPrice();
	$a_t = $a_item->getType();
	$b_t = $b_item->getType();
	$a_p = $a_item->getPrice();
	$b_p = $b_item->getPrice();

	if ($a_t < $b_t) {
		return -1;
	} elseif ($a_t > $b_t) {
		return 1;
	//} elseif ($a_t = $b_t) {
	} elseif ($a_t === $b_t) {
		if ($a_p > $b_p) {
			//return 1;
			return -1;
		//} elseif ($a_p = $b_p) {
		} elseif ($a_p === $b_p) {
			return 0;
		} elseif ($a_p < $b_p) {
			//return -1;
			return 1;
		}
	}
}

function solve(){
	$Scanner = new Scanner("php://stdin");
	//$Scanner = new Scanner("input.txt");

	$inp_N = (int)$Scanner->Scan();
	$inp_K = (int)$Scanner->Scan();

	for ($i = 0; $i < $inp_N; $i++) {
		$PRICE = $Scanner->Scan();
		$TYPE = (int)$Scanner->Scan();
		$ITEMS[] = new Item($i + 1, $TYPE, $PRICE);
	}

	//usort($ITEMS, array("ITEM", "compare"));
	usort($ITEMS, "compare");
	for ($i = 0; $i < $inp_N; $i++) {
		if ($i < $inp_K - 1) {
			//$KART[$i] = $ITEMS[$i]->getIndex();
			$KART[$i][] = $ITEMS[$i]->getIndex();
		} elseif ($i >= $inp_K - 1) {
			$KART[$inp_K - 1][] = $ITEMS[$i]->getIndex();
		}
	}

	for ($i = 0; $i < $inp_N; $i++) {
		$type = $ITEMS[$i]->getType();
		if ($i < $inp_K - 1 && $type === 1) {
			$sum += $ITEMS[$i]->getPrice() / 2;
		} elseif ($i >= $inp_K - 1 || $type !== 1) {
			$sum += $ITEMS[$i]->getPrice();
		}
	}

	//$min = 1E9 + 1;
	if ($ITEMS[$inp_K - 1]->getType() === 1) {
		$min = 1E9 + 1;
		for ($i = $inp_K - 1; $i < $inp_N; $i++) {
			$temp = $ITEMS[$i]->getPrice();
			$min = min($temp, $min);
		}
	}
	$sum -= $min / 2;

	printf("%.1f", $sum);
	print("\n");
	for ($i = 0; $i < $inp_K; $i++) {
		$count = count($KART[$i]);
		//print($sum);
		print($count);
		print(" ");
		$cou = 0;
		$c = 0;
		foreach ($KART[$i] as $as_i) {
			if ($i !== $inp_K - 1) {
				print($as_i);
				$cou++;
				//if ($cou != $count - 1) {
				if ($cou != $count) {
					print(" ");
				} else {
					print("\n");
				}
			} else {
				print($as_i);
				$c++;
				//if ($c != $count - 1) {
				if ($c != $count) {
					print(" ");
				}
			}
		}
	}
	$Scanner->close();
}

ob_end_clean();
solve();

//error_reporting(0);
//$Scanner = new Scanner("php://stdin");
class Scanner{
	private $Stream;
	private $Scanners = array();
	private $Id = 0;

	public function __construct($opend){
		if((!is_file($opend) && !is_link($opend)) && $opend !== "php://stdin"){
  			print("file or link or ''php://stdin' err");
  			exit;
		}

		$this->Stream = fopen($opend, 'r');
		$contents = stream_get_contents($this->Stream);

		//err $c_row = array("\n", "\r", "\r\n");
		$c_row = array("\r\n", "\r", "\n");
		$contents = str_replace($c_row, " ", $contents);
		$this->Scanners = explode(" ", $contents);
	}

	function Scan(){
		$x = $this->Id;
		$sc = $this->Scanners[$x];
		$this->Id = ++$x;
		return $sc;
	}

	function close(){
		fclose($this->Stream);
	}
}

/*
====begin=====

//input    $inp_ or upper
//block    $temp_
//two block$ttemp_
//as 	   $as_
//instance $(Upper)
//ref      $ref
//class menba $^Upper

====end=======

===== class begin =====

//error_reporting(0);
//$Scanner = new Scanner("php://stdin");
//ref "#109_div2_B_1230942 laurenceHR"
class LineScanner{
	private $Stream;
	private $Scanners = array();
	private $LineIds_Of_ScanIds= array();
	private $LinesScanners = array();
	private $LastScanIds_Of_LineIds = array();
	private $Scan_number = 0;
	private $Scanline_number = 0;

	public function __construct($opend){
		if((!is_file($opend) && !is_link($opend)) && $opend !== "php://stdin"){
  			print("file or link err");
  			exit;
		}

		$this->Stream = fopen($opend, 'r');
		$contents = stream_get_contents($this->Stream);

		$temp_lines = explode("\n", $contents);
		$temp_linescanners = array();
		$temp_x = 0;
		$temp_y = 0;
		//--attention for initting of array--(these is not needed but for easily reading)//
		$ttemp_scanners = array();
		//$del = Array("\n","\r","\n\r");
		foreach ($temp_lines as $as_line) {
			if (strlen($as_line) === 0) {
				print("input err");
			}

			//$as_line = str_replace($del,'',$as_line);
			$temp_linescanners[] = $as_line;
			$ttemp_line_scanners = explode(" ", $as_line);
			//$ttemp_scanners = array();
			foreach ($ttemp_line_scanners as $as_sc) {
				$ttemp_scanners[] = $as_sc;
				$this->LineIds_Of_ScanIds[$temp_x] = $temp_y;
				$temp_x++;
			}
			$this->LastScanIds_Of_LineIds[$temp_y] = $temp_x - 1;
			$temp_y++;
		}
		$this->Scanners = $ttemp_scanners;
		$this->LinesScanners = $temp_linescanners;
	}

	function Scan(){
		$x = $this->Scan_number;
		$y = $this->Scanline_number;
		if ($this->LineIds_Of_ScanIds[$x] === false || $this->LastScanIds_Of_LineIds[$y] === false) {
			print("scan err");
		}

		$sc = $this->Scanners[$x];
		//--attention for ++$x//
		//$this->Scan_number = $x++;
		$this->Scan_number = ++$x;
		$this->Scanline_number = $this->LineIds_Of_ScanIds[$x];
		return $sc;
	}

	function LineScan(){
		$x = $this->Scan_number;
		$y = $this->Scanline_number;
		if ($this->LineIds_Of_ScanIds[$x] === false || $this->LastScanIds_Of_LineIds[$y] === false) {
			print("linescan err");
		}

		$lsc = $this->LinesScanners[$y];
		$this->Scan_number = $this->LastScanIds_Of_LineIds[$y] + 1;
		$this->Scanline_number = $y + 1;
		return $lsc;
	}

	function close(){
		fclose($this->Stream);
	}
}

class Token{
	private $token;
	private $tok;

	public function __construct($str_line, $tok) {
		$this->tok = $tok;
		$this->token = strtok($str_line, $this->tok);
	}

	public function nextToken() {
		$thisToken = $this->token;
		$this->token = strtok($this->tok);
		return $thisToken;
	}

	public function nextFloat() {
		return (float)$this->nextToken();
	}

  	public function nextInt() {
		return (int)$this->nextToken();
	}

	public function nextIntArray() {
		$temp_arr = array();
		$flag = -1;
		while ($flag !== 1) {
			$thisToken = $this->nextToken();
			if ($thisToken !== false) {
				$temp_arr[] = $thisToken;
			} else {
				$flag = 1;
			}
		}
		return $temp_arr;
	}

	public function nnextIntArray($num) {
		$temp_arr = array();
		for ($i = 0; $i < $num; $i++) {
			$temp_arr[] = (int)$this->token;
		}
		return $temp_arr;
	}
}
===== class end ======

=== function begin ===

function get_line() {
        $stdin = fopen("php://stdin", "r");
        $line = rtrim($stdin, "\n");
        fclose($stdin);
        return $line;
}

function num_printf($i){
	if (is_float($i)) {
		printf("%.0f", $i);
	}
	if (is_int($i)) {
		printf("%d", $i);
	}
}

function array_printf(array $array) {
		$message = "";
		foreach ($array as $value) {
			$message .= "$value" . " ";
		}
		$message = rtrim($message);
		printf('%s', $message);
}

== function end ======
*/

?>

<?php
error_reporting(0);

class Item{
	private $index;
	private $type;
	private $price;

	public function __construct($index, $type, $price) {
		$this->index = $index;
		$this->type = $type;
		$this->price = $price;
	}

	public function getIndex() {
		return $this->index;
	}

	public function getPrice() {
		return $this->price;
	}

	public function getType() {
		return $this->type;
	}

    static function compareItem($a_item, $b_item) {
		$a_t = $a_item->getType();
		$b_t = $b_item->getType();
		$a_p = $a_item->getPrice();
		$b_p = $b_item->getPrice();

		if ($a_t < $b_t) return -1;
		elseif ($a_t > $b_t) return 1;
		elseif ($a_t === $b_t) {
			if ($a_p > $b_p) return -1;
			elseif ($a_p === $b_p) return 0;
			elseif ($a_p < $b_p) return 1;
		}
	}
}
/*
function compare(Item $a_item , Item $b_item){
	//$a_t = $a->getType();
	//$b_t = $b->getType();
	//$a_p = $a->getPrice();
	//$b_p = $b->getPrice();
	$a_t = $a_item->getType();
	$b_t = $b_item->getType();
	$a_p = $a_item->getPrice();
	$b_p = $b_item->getPrice();

	if ($a_t < $b_t) {
		return -1;
	} elseif ($a_t > $b_t) {
		return 1;
	//} elseif ($a_t = $b_t) {
	} elseif ($a_t === $b_t) {
		if ($a_p > $b_p) {
			//return 1;
			return -1;
		//} elseif ($a_p = $b_p) {
		} elseif ($a_p === $b_p) {
			return 0;
		} elseif ($a_p < $b_p) {
			//return -1;
			return 1;
		}
	}
}
*/
function solve(){
	$Scanner = new Scanner("php://stdin");
	//$Scanner = new Scanner("input.txt");

	$inp_N = (int)$Scanner->Scan();
	$inp_K = (int)$Scanner->Scan();

	for ($i = 0; $i < $inp_N; $i++) {
		$PRICE = $Scanner->Scan();
		$TYPE = (int)$Scanner->Scan();
		$ITEMS[] = new Item($i + 1, $TYPE, $PRICE);
	}

	usort($ITEMS, array("Item", "compareItem"));
	//usort($ITEMS, "compare");
	for ($i = 0; $i < $inp_N; $i++) {
		if ($i < $inp_K - 1) {
			//$KART[$i] = $ITEMS[$i]->getIndex();
			$KART[$i][] = $ITEMS[$i]->getIndex();
		} elseif ($i >= $inp_K - 1) {
			$KART[$inp_K - 1][] = $ITEMS[$i]->getIndex();
		}
	}

	for ($i = 0; $i < $inp_N; $i++) {
		$type = $ITEMS[$i]->getType();
		if ($i < $inp_K - 1 && $type === 1) {
			$sum += $ITEMS[$i]->getPrice() / 2;
		} elseif ($i >= $inp_K - 1 || $type !== 1) {
			$sum += $ITEMS[$i]->getPrice();
		}
	}

	//$min = 1E9 + 1;
	if ($ITEMS[$inp_K - 1]->getType() === 1) {
		$min = 1E9 + 1;
		for ($i = $inp_K - 1; $i < $inp_N; $i++) {
			$temp = $ITEMS[$i]->getPrice();
			$min = min($temp, $min);
		}
	}
	$sum -= $min / 2;

	printf("%.1f", $sum);
	print("\n");
	for ($i = 0; $i < $inp_K; $i++) {
		$count = count($KART[$i]);
		//print($sum);
		print($count);
		print(" ");
		$cou = 0;
		$c = 0;
		foreach ($KART[$i] as $as_i) {
			if ($i !== $inp_K - 1) {
				print($as_i);
				$cou++;
				//if ($cou != $count - 1) {
				if ($cou != $count) {
					print(" ");
				} else {
					print("\n");
				}
			} else {
				print($as_i);
				$c++;
				//if ($c != $count - 1) {
				if ($c != $count) {
					print(" ");
				}
			}
		}
	}
	$Scanner->close();
}

ob_end_clean();
solve();

//error_reporting(0);
//$Scanner = new Scanner("php://stdin");
class Scanner{
	private $Stream;
	private $Scanners = array();
	private $Id = 0;

	public function __construct($opend){
		if((!is_file($opend) && !is_link($opend)) && $opend !== "php://stdin"){
  			print("file or link or ''php://stdin' err");
  			exit;
		}

		$this->Stream = fopen($opend, 'r');
		$contents = stream_get_contents($this->Stream);

		//err $c_row = array("\n", "\r", "\r\n");
		$c_row = array("\r\n", "\r", "\n");
		$contents = str_replace($c_row, " ", $contents);
		$this->Scanners = explode(" ", $contents);
	}

	function Scan(){
		$x = $this->Id;
		$sc = $this->Scanners[$x];
		$this->Id = ++$x;
		return $sc;
	}

	function close(){
		fclose($this->Stream);
	}
}

/*
====begin=====

//input    $inp_ or upper
//block    $temp_
//two block$ttemp_
//as 	   $as_
//instance $(Upper)
//ref      $ref
//class menba $^Upper

====end=======

===== class begin =====

//error_reporting(0);
//$Scanner = new Scanner("php://stdin");
//ref "#109_div2_B_1230942 laurenceHR"
class LineScanner{
	private $Stream;
	private $Scanners = array();
	private $LineIds_Of_ScanIds= array();
	private $LinesScanners = array();
	private $LastScanIds_Of_LineIds = array();
	private $Scan_number = 0;
	private $Scanline_number = 0;

	public function __construct($opend){
		if((!is_file($opend) && !is_link($opend)) && $opend !== "php://stdin"){
  			print("file or link err");
  			exit;
		}

		$this->Stream = fopen($opend, 'r');
		$contents = stream_get_contents($this->Stream);

		$temp_lines = explode("\n", $contents);
		$temp_linescanners = array();
		$temp_x = 0;
		$temp_y = 0;
		//--attention for initting of array--(these is not needed but for easily reading)//
		$ttemp_scanners = array();
		//$del = Array("\n","\r","\n\r");
		foreach ($temp_lines as $as_line) {
			if (strlen($as_line) === 0) {
				print("input err");
			}

			//$as_line = str_replace($del,'',$as_line);
			$temp_linescanners[] = $as_line;
			$ttemp_line_scanners = explode(" ", $as_line);
			//$ttemp_scanners = array();
			foreach ($ttemp_line_scanners as $as_sc) {
				$ttemp_scanners[] = $as_sc;
				$this->LineIds_Of_ScanIds[$temp_x] = $temp_y;
				$temp_x++;
			}
			$this->LastScanIds_Of_LineIds[$temp_y] = $temp_x - 1;
			$temp_y++;
		}
		$this->Scanners = $ttemp_scanners;
		$this->LinesScanners = $temp_linescanners;
	}

	function Scan(){
		$x = $this->Scan_number;
		$y = $this->Scanline_number;
		if ($this->LineIds_Of_ScanIds[$x] === false || $this->LastScanIds_Of_LineIds[$y] === false) {
			print("scan err");
		}

		$sc = $this->Scanners[$x];
		//--attention for ++$x//
		//$this->Scan_number = $x++;
		$this->Scan_number = ++$x;
		$this->Scanline_number = $this->LineIds_Of_ScanIds[$x];
		return $sc;
	}

	function LineScan(){
		$x = $this->Scan_number;
		$y = $this->Scanline_number;
		if ($this->LineIds_Of_ScanIds[$x] === false || $this->LastScanIds_Of_LineIds[$y] === false) {
			print("linescan err");
		}

		$lsc = $this->LinesScanners[$y];
		$this->Scan_number = $this->LastScanIds_Of_LineIds[$y] + 1;
		$this->Scanline_number = $y + 1;
		return $lsc;
	}

	function close(){
		fclose($this->Stream);
	}
}

class Token{
	private $token;
	private $tok;

	public function __construct($str_line, $tok) {
		$this->tok = $tok;
		$this->token = strtok($str_line, $this->tok);
	}

	public function nextToken() {
		$thisToken = $this->token;
		$this->token = strtok($this->tok);
		return $thisToken;
	}

	public function nextFloat() {
		return (float)$this->nextToken();
	}

  	public function nextInt() {
		return (int)$this->nextToken();
	}

	public function nextIntArray() {
		$temp_arr = array();
		$flag = -1;
		while ($flag !== 1) {
			$thisToken = $this->nextToken();
			if ($thisToken !== false) {
				$temp_arr[] = $thisToken;
			} else {
				$flag = 1;
			}
		}
		return $temp_arr;
	}

	public function nnextIntArray($num) {
		$temp_arr = array();
		for ($i = 0; $i < $num; $i++) {
			$temp_arr[] = (int)$this->token;
		}
		return $temp_arr;
	}
}
===== class end ======

=== function begin ===

function get_line() {
        $stdin = fopen("php://stdin", "r");
        $line = rtrim($stdin, "\n");
        fclose($stdin);
        return $line;
}

function num_printf($i){
	if (is_float($i)) {
		printf("%.0f", $i);
	}
	if (is_int($i)) {
		printf("%d", $i);
	}
}

function array_printf(array $array) {
		$message = "";
		foreach ($array as $value) {
			$message .= "$value" . " ";
		}
		$message = rtrim($message);
		printf('%s', $message);
}

== function end ======
*/

?>

<?php
error_reporting(0);

function solve(){
	$Scanner = new Scanner("php://stdin");
	//$Scanner = new Scanner("input.txt");

	$inp_N = (int)$Scanner->Scan();
	$inp_K = (int)$Scanner->Scan();

	for ($i = 0; $i < $inp_N; $i++) {
		 $PRICE = $Scanner->Scan();
		 $TYPE = (int)$Scanner->Scan();
		 if ($TYPE === 1) $STOOLS[$i + 1] = $PRICE;
		 else if ($TYPE === 2) $PENCILS[$i + 1] = $PRICE;
	}

	//if (!asort($STOOLS)) print("err");
	//In case $STOOLS is null, this is printed;

	asort($STOOLS);
	asort($PENCILS);
	$min = 0;
	$sum = 0;
	$num = 0;
	$diff = count($STOOLS) - $inp_K;
	if ($diff >= 0) {
		foreach ($STOOLS as $STOOLS_key => $STOOLS_val) {
			if ($num <= $diff) {
				if ($num === 0) $min = $STOOLS_val / 2;
				else $sum += $STOOLS_val;
				$KART[0][] = $STOOLS_key;
			} else {
				$sum += $STOOLS_val / 2;
				$KART[$num - $diff][] = $STOOLS_key;
			}
			$num++;
		}

		$PEN_FLAG = 0;
		foreach ($PENCILS as $PENCILS_key => $PENCILS_val) {
			if ($PEN_FLAG === 0) {
				//$min = min($min, $PENCILS_val / 2) + ;
				if ($min > $PENCILS_val / 2) $min = $PENCILS_val / 2 + 2 * $min;
				elseif ($min <= $PENCILS_val / 2) $min = $PENCILS_val + $min;
				$PEN_FLAG = 1;
			} else {
				$sum += $PENCILS_val;
			}
			$KART[0][] = $PENCILS_key;
		}
		$sum = $sum + $min;
	} elseif($diff < 0)	{
		foreach ($STOOLS as $STOOLS_key => $STOOLS_val) {
			$sum += $STOOLS_val / 2;
			$KART[$num][] = $STOOLS_key;
			$num++;
		}

		foreach ($PENCILS as $PENCILS_key => $PENCILS_val) {
			if ($diff !== 0) {
				$sum += $PENCILS_val;
				$KART[$num][] = $PENCILS_key;
				$diff++;
				$num++;
			} else {
				$sum += $PENCILS_val;
				$KART[$inp_K - 1][] = $PENCILS_key;
			}
		}
	}
	printf("%.1f", $sum);
	print("\n");
	for ($i = 0; $i < $inp_K; $i++) {
		$count = count($KART[$i]);
		//print($sum);
		print($count);
		print(" ");
		$cou = 0;
		$c = 0;
		foreach ($KART[$i] as $as_i) {
			if ($i !== $inp_K - 1) {
				print($as_i);
				$cou++;
				//if ($cou != $count - 1) {
				if ($cou != $count) {
					print(" ");
				} else {
					print("\n");
				}
			} else {
				print($as_i);
				$c++;
				//if ($c != $count - 1) {
				if ($c != $count) {
					print(" ");
				}
			}
		}
	}
	$Scanner->close();
}

ob_end_clean();
solve();

//error_reporting(0);
//$Scanner = new Scanner("php://stdin");
class Scanner{
	private $Stream;
	private $Scanners = array();
	private $Id = 0;

	public function __construct($opend){
		if((!is_file($opend) && !is_link($opend)) && $opend !== "php://stdin"){
  			print("file or link or ''php://stdin' err");
  			exit;
		}

		$this->Stream = fopen($opend, 'r');
		$contents = stream_get_contents($this->Stream);

		//err $c_row = array("\n", "\r", "\r\n");
		$c_row = array("\r\n", "\r", "\n");
		$contents = str_replace($c_row, " ", $contents);
		$this->Scanners = explode(" ", $contents);
	}

	function Scan(){
		$x = $this->Id;
		$sc = $this->Scanners[$x];
		$this->Id = ++$x;
		return $sc;
	}

	function close(){
		fclose($this->Stream);
	}
}

/*
====begin=====

//input    $inp_ or upper
//block    $temp_
//two block$ttemp_
//as 	   $as_
//instance $(Upper)
//ref      $ref
//class menba $^Upper

====end=======

===== class begin =====

//error_reporting(0);
//$Scanner = new Scanner("php://stdin");
//ref "#109_div2_B_1230942 laurenceHR"
class LineScanner{
	private $Stream;
	private $Scanners = array();
	private $LineIds_Of_ScanIds= array();
	private $LinesScanners = array();
	private $LastScanIds_Of_LineIds = array();
	private $Scan_number = 0;
	private $Scanline_number = 0;

	public function __construct($opend){
		if((!is_file($opend) && !is_link($opend)) && $opend !== "php://stdin"){
  			print("file or link err");
  			exit;
		}

		$this->Stream = fopen($opend, 'r');
		$contents = stream_get_contents($this->Stream);

		$temp_lines = explode("\n", $contents);
		$temp_linescanners = array();
		$temp_x = 0;
		$temp_y = 0;
		//--attention for initting of array--(these is not needed but for easily reading)//
		$ttemp_scanners = array();
		//$del = Array("\n","\r","\n\r");
		foreach ($temp_lines as $as_line) {
			if (strlen($as_line) === 0) {
				print("input err");
			}

			//$as_line = str_replace($del,'',$as_line);
			$temp_linescanners[] = $as_line;
			$ttemp_line_scanners = explode(" ", $as_line);
			//$ttemp_scanners = array();
			foreach ($ttemp_line_scanners as $as_sc) {
				$ttemp_scanners[] = $as_sc;
				$this->LineIds_Of_ScanIds[$temp_x] = $temp_y;
				$temp_x++;
			}
			$this->LastScanIds_Of_LineIds[$temp_y] = $temp_x - 1;
			$temp_y++;
		}
		$this->Scanners = $ttemp_scanners;
		$this->LinesScanners = $temp_linescanners;
	}

	function Scan(){
		$x = $this->Scan_number;
		$y = $this->Scanline_number;
		if ($this->LineIds_Of_ScanIds[$x] === false || $this->LastScanIds_Of_LineIds[$y] === false) {
			print("scan err");
		}

		$sc = $this->Scanners[$x];
		//--attention for ++$x//
		//$this->Scan_number = $x++;
		$this->Scan_number = ++$x;
		$this->Scanline_number = $this->LineIds_Of_ScanIds[$x];
		return $sc;
	}

	function LineScan(){
		$x = $this->Scan_number;
		$y = $this->Scanline_number;
		if ($this->LineIds_Of_ScanIds[$x] === false || $this->LastScanIds_Of_LineIds[$y] === false) {
			print("linescan err");
		}

		$lsc = $this->LinesScanners[$y];
		$this->Scan_number = $this->LastScanIds_Of_LineIds[$y] + 1;
		$this->Scanline_number = $y + 1;
		return $lsc;
	}

	function close(){
		fclose($this->Stream);
	}
}

class Token{
	private $token;
	private $tok;

	public function __construct($str_line, $tok) {
		$this->tok = $tok;
		$this->token = strtok($str_line, $this->tok);
	}

	public function nextToken() {
		$thisToken = $this->token;
		$this->token = strtok($this->tok);
		return $thisToken;
	}

	public function nextFloat() {
		return (float)$this->nextToken();
	}

  	public function nextInt() {
		return (int)$this->nextToken();
	}

	public function nextIntArray() {
		$temp_arr = array();
		$flag = -1;
		while ($flag !== 1) {
			$thisToken = $this->nextToken();
			if ($thisToken !== false) {
				$temp_arr[] = $thisToken;
			} else {
				$flag = 1;
			}
		}
		return $temp_arr;
	}

	public function nnextIntArray($num) {
		$temp_arr = array();
		for ($i = 0; $i < $num; $i++) {
			$temp_arr[] = (int)$this->token;
		}
		return $temp_arr;
	}
}
===== class end ======

=== function begin ===

function get_line() {
        $stdin = fopen("php://stdin", "r");
        $line = rtrim($stdin, "\n");
        fclose($stdin);
        return $line;
}

function num_printf($i){
	if (is_float($i)) {
		printf("%.0f", $i);
	}
	if (is_int($i)) {
		printf("%d", $i);
	}
}

function array_printf(array $array) {
		$message = "";
		foreach ($array as $value) {
			$message .= "$value" . " ";
		}
		$message = rtrim($message);
		printf('%s', $message);
}

== function end ======
*/

?>

<?php
error_reporting(0);

function solve(){
	$Scanner = new Scanner("php://stdin");
	//$Scanner = new Scanner("input.txt");

	$inp_N = (int)$Scanner->Scan();
	$inp_K = (int)$Scanner->Scan();

	for ($i = 0; $i < $inp_N; $i++) {
		$PRICE = $Scanner->Scan();
		$TYPE = (int)$Scanner->Scan();
		if ($TYPE === 1) $ITEMS[$i][] = $TYPE + 2;
		else $ITEMS[$i][] = $TYPE;
		$ITEMS[$i][] = $PRICE;
	}

	arsort($ITEMS);
	$keys = array_keys($ITEMS);
	for ($i = 0; $i < $inp_N; $i++) {
		if ($i < $inp_K - 1) {
			$KART[$i][] = $keys[$i] + 1;
		} elseif ($i >= $inp_K - 1) {
			$KART[$inp_K - 1][] = $keys[$i] + 1;
		}
	}

	for ($i = 0; $i < $inp_N; $i++) {
		$type = $ITEMS[$i][0];
		if ($i < $inp_K - 1 && $type === 3) {
			$sum += $ITEMS[$i][1] / 2;
		} elseif ($i >= $inp_K - 1 || $type !== 3) {
			$sum += $ITEMS[$i][1];
		}
	}

	if ($keys[$inp_K - 1] === 3) {
		$min = 1E9 + 1;
		for ($i = $inp_K - 1; $i < $inp_N; $i++) {
			$temp = $ITEMS[$i][1];
			$min = min($temp, $min);
		}
	}
	$sum -= $min / 2;

	printf("%.1f", $sum);
	print("\n");
	for ($i = 0; $i < $inp_K; $i++) {
		$count = count($KART[$i]);
		print($count);
		print(" ");
		$cou = 0;
		$c = 0;
		foreach ($KART[$i] as $as_i) {
			if ($i !== $inp_K - 1) {
				print($as_i);
				$cou++;
				if ($cou != $count) {
					print(" ");
				} else {
					print("\n");
				}
			} else {
				print($as_i);
				$c++;
				if ($c != $count) {
					print(" ");
				}
			}
		}
	}
	$Scanner->close();
}

ob_end_clean();
solve();

//error_reporting(0);
//$Scanner = new Scanner("php://stdin");
class Scanner{
	private $Stream;
	private $Scanners = array();
	private $Id = 0;

	public function __construct($opend){
		if((!is_file($opend) && !is_link($opend)) && $opend !== "php://stdin"){
  			print("file or link or ''php://stdin' err");
  			exit;
		}

		$this->Stream = fopen($opend, 'r');
		$contents = stream_get_contents($this->Stream);

		//err $c_row = array("\n", "\r", "\r\n");
		$c_row = array("\r\n", "\r", "\n");
		$contents = str_replace($c_row, " ", $contents);
		$this->Scanners = explode(" ", $contents);
	}

	function Scan(){
		$x = $this->Id;
		$sc = $this->Scanners[$x];
		$this->Id = ++$x;
		return $sc;
	}

	function close(){
		fclose($this->Stream);
	}
}

/*
====begin=====

//input    $inp_ or upper
//block    $temp_
//two block$ttemp_
//as 	   $as_
//instance $(Upper)
//ref      $ref
//class menba $^Upper

====end=======

===== class begin =====

//error_reporting(0);
//$Scanner = new Scanner("php://stdin");
//ref "#109_div2_B_1230942 laurenceHR"
class LineScanner{
	private $Stream;
	private $Scanners = array();
	private $LineIds_Of_ScanIds= array();
	private $LinesScanners = array();
	private $LastScanIds_Of_LineIds = array();
	private $Scan_number = 0;
	private $Scanline_number = 0;

	public function __construct($opend){
		if((!is_file($opend) && !is_link($opend)) && $opend !== "php://stdin"){
  			print("file or link err");
  			exit;
		}

		$this->Stream = fopen($opend, 'r');
		$contents = stream_get_contents($this->Stream);

		$temp_lines = explode("\n", $contents);
		$temp_linescanners = array();
		$temp_x = 0;
		$temp_y = 0;
		//--attention for initting of array--(these is not needed but for easily reading)//
		$ttemp_scanners = array();
		//$del = Array("\n","\r","\n\r");
		foreach ($temp_lines as $as_line) {
			if (strlen($as_line) === 0) {
				print("input err");
			}

			//$as_line = str_replace($del,'',$as_line);
			$temp_linescanners[] = $as_line;
			$ttemp_line_scanners = explode(" ", $as_line);
			//$ttemp_scanners = array();
			foreach ($ttemp_line_scanners as $as_sc) {
				$ttemp_scanners[] = $as_sc;
				$this->LineIds_Of_ScanIds[$temp_x] = $temp_y;
				$temp_x++;
			}
			$this->LastScanIds_Of_LineIds[$temp_y] = $temp_x - 1;
			$temp_y++;
		}
		$this->Scanners = $ttemp_scanners;
		$this->LinesScanners = $temp_linescanners;
	}

	function Scan(){
		$x = $this->Scan_number;
		$y = $this->Scanline_number;
		if ($this->LineIds_Of_ScanIds[$x] === false || $this->LastScanIds_Of_LineIds[$y] === false) {
			print("scan err");
		}

		$sc = $this->Scanners[$x];
		//--attention for ++$x//
		//$this->Scan_number = $x++;
		$this->Scan_number = ++$x;
		$this->Scanline_number = $this->LineIds_Of_ScanIds[$x];
		return $sc;
	}

	function LineScan(){
		$x = $this->Scan_number;
		$y = $this->Scanline_number;
		if ($this->LineIds_Of_ScanIds[$x] === false || $this->LastScanIds_Of_LineIds[$y] === false) {
			print("linescan err");
		}

		$lsc = $this->LinesScanners[$y];
		$this->Scan_number = $this->LastScanIds_Of_LineIds[$y] + 1;
		$this->Scanline_number = $y + 1;
		return $lsc;
	}

	function close(){
		fclose($this->Stream);
	}
}

class Token{
	private $token;
	private $tok;

	public function __construct($str_line, $tok) {
		$this->tok = $tok;
		$this->token = strtok($str_line, $this->tok);
	}

	public function nextToken() {
		$thisToken = $this->token;
		$this->token = strtok($this->tok);
		return $thisToken;
	}

	public function nextFloat() {
		return (float)$this->nextToken();
	}

  	public function nextInt() {
		return (int)$this->nextToken();
	}

	public function nextIntArray() {
		$temp_arr = array();
		$flag = -1;
		while ($flag !== 1) {
			$thisToken = $this->nextToken();
			if ($thisToken !== false) {
				$temp_arr[] = $thisToken;
			} else {
				$flag = 1;
			}
		}
		return $temp_arr;
	}

	public function nnextIntArray($num) {
		$temp_arr = array();
		for ($i = 0; $i < $num; $i++) {
			$temp_arr[] = (int)$this->token;
		}
		return $temp_arr;
	}
}
===== class end ======

=== function begin ===

function get_line() {
        $stdin = fopen("php://stdin", "r");
        $line = rtrim($stdin, "\n");
        fclose($stdin);
        return $line;
}

function num_printf($i){
	if (is_float($i)) {
		printf("%.0f", $i);
	}
	if (is_int($i)) {
		printf("%d", $i);
	}
}

function array_printf(array $array) {
		$message = "";
		foreach ($array as $value) {
			$message .= "$value" . " ";
		}
		$message = rtrim($message);
		printf('%s', $message);
}

== function end ======
*/

?>

<?php
error_reporting(0);

class Item{
	private $index;
	private $type;
	private $price;

	public function __construct($index, $type, $price) {
		$this->index = $index;
		$this->type = $type;
		$this->price = $price;
	}

	public function getIndex() {
		return $this->index;
	}

	public function getPrice() {
		return $this->price;
	}

	public function getType() {
		return $this->type;
	}

    static function compareItem($a_item, $b_item) {
		$a_t = $a_item->getType();
		$b_t = $b_item->getType();
		$a_p = $a_item->getPrice();
		$b_p = $b_item->getPrice();

		if ($a_t < $b_t) return -1;
		elseif ($a_t > $b_t) return 1;
		elseif ($a_t === $b_t) {
			if ($a_p > $b_p) return -1;
			elseif ($a_p === $b_p) return 0;
			elseif ($a_p < $b_p) return 1;
		}
	}
}
/*
function compare(Item $a_item , Item $b_item){
	//$a_t = $a->getType();
	//$b_t = $b->getType();
	//$a_p = $a->getPrice();
	//$b_p = $b->getPrice();
	$a_t = $a_item->getType();
	$b_t = $b_item->getType();
	$a_p = $a_item->getPrice();
	$b_p = $b_item->getPrice();

	if ($a_t < $b_t) {
		return -1;
	} elseif ($a_t > $b_t) {
		return 1;
	//} elseif ($a_t = $b_t) {
	} elseif ($a_t === $b_t) {
		if ($a_p > $b_p) {
			//return 1;
			return -1;
		//} elseif ($a_p = $b_p) {
		} elseif ($a_p === $b_p) {
			return 0;
		} elseif ($a_p < $b_p) {
			//return -1;
			return 1;
		}
	}
}
*/
function solve(){
	//$Scanner = new Scanner("php://stdin");
	$Scanner = new Scanner("input.txt");

	$inp_N = (int)$Scanner->Scan();
	$inp_K = (int)$Scanner->Scan();

	for ($i = 0; $i < $inp_N; $i++) {
		$PRICE = $Scanner->Scan();
		$TYPE = (int)$Scanner->Scan();
		$ITEMS[] = new Item($i + 1, $TYPE, $PRICE);
	}

	usort($ITEMS, array("Item", "compareItem"));
	//usort($ITEMS, "compare");
	for ($i = 0; $i < $inp_N; $i++) {
		if ($i < $inp_K - 1) {
			//$KART[$i] = $ITEMS[$i]->getIndex();
			$KART[$i][] = $ITEMS[$i]->getIndex();
		} elseif ($i >= $inp_K - 1) {
			$KART[$inp_K - 1][] = $ITEMS[$i]->getIndex();
		}
	}

	for ($i = 0; $i < $inp_N; $i++) {
		$type = $ITEMS[$i]->getType();
		if ($i < $inp_K - 1 && $type === 1) {
			$sum += $ITEMS[$i]->getPrice() / 2;
		} elseif ($i >= $inp_K - 1 || $type !== 1) {
			$sum += $ITEMS[$i]->getPrice();
		}
	}

	//$min = 1E9 + 1;
	if ($ITEMS[$inp_K - 1]->getType() === 1) {
		$min = 1E9 + 1;
		for ($i = $inp_K - 1; $i < $inp_N; $i++) {
			$temp = $ITEMS[$i]->getPrice();
			$min = min($temp, $min);
		}
	}
	$sum -= $min / 2;

	printf("%.1f", $sum);
	print("\n");
	for ($i = 0; $i < $inp_K; $i++) {
		$count = count($KART[$i]);
		//print($sum);
		print($count);
		print(" ");
		$cou = 0;
		$c = 0;
		foreach ($KART[$i] as $as_i) {
			if ($i !== $inp_K - 1) {
				print($as_i);
				$cou++;
				//if ($cou != $count - 1) {
				if ($cou != $count) {
					print(" ");
				} else {
					print("\n");
				}
			} else {
				print($as_i);
				$c++;
				//if ($c != $count - 1) {
				if ($c != $count) {
					print(" ");
				}
			}
		}
	}
	$Scanner->close();
}

ob_end_clean();
solve();

//error_reporting(0);
//$Scanner = new Scanner("php://stdin");
class Scanner{
	private $Stream;
	private $Scanners = array();
	private $Id = 0;

	public function __construct($opend){
		if((!is_file($opend) && !is_link($opend)) && $opend !== "php://stdin"){
  			print("file or link or ''php://stdin' err");
  			exit;
		}

		$this->Stream = fopen($opend, 'r');
		$contents = stream_get_contents($this->Stream);

		//err $c_row = array("\n", "\r", "\r\n");
		$c_row = array("\r\n", "\r", "\n");
		$contents = str_replace($c_row, " ", $contents);
		$this->Scanners = explode(" ", $contents);
	}

	function Scan(){
		$x = $this->Id;
		$sc = $this->Scanners[$x];
		$this->Id = ++$x;
		return $sc;
	}

	function close(){
		fclose($this->Stream);
	}
}

/*
====begin=====

//input    $inp_ or upper
//block    $temp_
//two block$ttemp_
//as 	   $as_
//instance $(Upper)
//ref      $ref
//class menba $^Upper

====end=======

===== class begin =====

//error_reporting(0);
//$Scanner = new Scanner("php://stdin");
//ref "#109_div2_B_1230942 laurenceHR"
class LineScanner{
	private $Stream;
	private $Scanners = array();
	private $LineIds_Of_ScanIds= array();
	private $LinesScanners = array();
	private $LastScanIds_Of_LineIds = array();
	private $Scan_number = 0;
	private $Scanline_number = 0;

	public function __construct($opend){
		if((!is_file($opend) && !is_link($opend)) && $opend !== "php://stdin"){
  			print("file or link err");
  			exit;
		}

		$this->Stream = fopen($opend, 'r');
		$contents = stream_get_contents($this->Stream);

		$temp_lines = explode("\n", $contents);
		$temp_linescanners = array();
		$temp_x = 0;
		$temp_y = 0;
		//--attention for initting of array--(these is not needed but for easily reading)//
		$ttemp_scanners = array();
		//$del = Array("\n","\r","\n\r");
		foreach ($temp_lines as $as_line) {
			if (strlen($as_line) === 0) {
				print("input err");
			}

			//$as_line = str_replace($del,'',$as_line);
			$temp_linescanners[] = $as_line;
			$ttemp_line_scanners = explode(" ", $as_line);
			//$ttemp_scanners = array();
			foreach ($ttemp_line_scanners as $as_sc) {
				$ttemp_scanners[] = $as_sc;
				$this->LineIds_Of_ScanIds[$temp_x] = $temp_y;
				$temp_x++;
			}
			$this->LastScanIds_Of_LineIds[$temp_y] = $temp_x - 1;
			$temp_y++;
		}
		$this->Scanners = $ttemp_scanners;
		$this->LinesScanners = $temp_linescanners;
	}

	function Scan(){
		$x = $this->Scan_number;
		$y = $this->Scanline_number;
		if ($this->LineIds_Of_ScanIds[$x] === false || $this->LastScanIds_Of_LineIds[$y] === false) {
			print("scan err");
		}

		$sc = $this->Scanners[$x];
		//--attention for ++$x//
		//$this->Scan_number = $x++;
		$this->Scan_number = ++$x;
		$this->Scanline_number = $this->LineIds_Of_ScanIds[$x];
		return $sc;
	}

	function LineScan(){
		$x = $this->Scan_number;
		$y = $this->Scanline_number;
		if ($this->LineIds_Of_ScanIds[$x] === false || $this->LastScanIds_Of_LineIds[$y] === false) {
			print("linescan err");
		}

		$lsc = $this->LinesScanners[$y];
		$this->Scan_number = $this->LastScanIds_Of_LineIds[$y] + 1;
		$this->Scanline_number = $y + 1;
		return $lsc;
	}

	function close(){
		fclose($this->Stream);
	}
}

class Token{
	private $token;
	private $tok;

	public function __construct($str_line, $tok) {
		$this->tok = $tok;
		$this->token = strtok($str_line, $this->tok);
	}

	public function nextToken() {
		$thisToken = $this->token;
		$this->token = strtok($this->tok);
		return $thisToken;
	}

	public function nextFloat() {
		return (float)$this->nextToken();
	}

  	public function nextInt() {
		return (int)$this->nextToken();
	}

	public function nextIntArray() {
		$temp_arr = array();
		$flag = -1;
		while ($flag !== 1) {
			$thisToken = $this->nextToken();
			if ($thisToken !== false) {
				$temp_arr[] = $thisToken;
			} else {
				$flag = 1;
			}
		}
		return $temp_arr;
	}

	public function nnextIntArray($num) {
		$temp_arr = array();
		for ($i = 0; $i < $num; $i++) {
			$temp_arr[] = (int)$this->token;
		}
		return $temp_arr;
	}
}
===== class end ======

=== function begin ===

function get_line() {
        $stdin = fopen("php://stdin", "r");
        $line = rtrim($stdin, "\n");
        fclose($stdin);
        return $line;
}

function num_printf($i){
	if (is_float($i)) {
		printf("%.0f", $i);
	}
	if (is_int($i)) {
		printf("%d", $i);
	}
}

function array_printf(array $array) {
		$message = "";
		foreach ($array as $value) {
			$message .= "$value" . " ";
		}
		$message = rtrim($message);
		printf('%s', $message);
}

== function end ======
*/

?>

<?php
error_reporting(0);

function solve(){
	$Scanner = new Scanner("php://stdin");
	//$Scanner = new Scanner("input.txt");

	$inp_N = (int)$Scanner->Scan();
	$inp_K = (int)$Scanner->Scan();

	for ($i = 0; $i < $inp_N; $i++) {
		$PRICE = $Scanner->Scan();
		$TYPE = (int)$Scanner->Scan();
		if ($TYPE === 1) $ITEMS[$i][] = $TYPE + 2;
		else $ITEMS[$i][] = $TYPE;
		$ITEMS[$i][] = $PRICE;
	}

	arsort($ITEMS);
	$keys = array_keys($ITEMS);
	for ($i = 0; $i < $inp_N; $i++) {
		if ($i < $inp_K - 1) {
			$KART[$i][] = $keys[$i] + 1;
		} elseif ($i >= $inp_K - 1) {
			$KART[$inp_K - 1][] = $keys[$i] + 1;
		}
	}

	for ($i = 0; $i < $inp_N; $i++) {
		$type = $ITEMS[$i][0];
		if ($i < $inp_K - 1 && $type === 3) {
			$sum += $ITEMS[$i][1] / 2;
		} elseif ($i >= $inp_K - 1 || $type !== 3) {
			$sum += $ITEMS[$i][1];
		}
	}

	//if ($ITEMS[$inp_K - 1][0] === 3) {
	if ($ITEMS[$keys[$inp_K - 1]][0] === 3) {
		$min = 1E9 + 1;
		for ($i = $inp_K - 1; $i < $inp_N; $i++) {
			$temp = $ITEMS[$keys[$i]][1];
			$min = min($temp, $min);
		}
	}
	$sum -= $min / 2;

	printf("%.1f", $sum);
	print("\n");
	for ($i = 0; $i < $inp_K; $i++) {
		$count = count($KART[$i]);
		print($count);
		print(" ");
		$cou = 0;
		$c = 0;
		foreach ($KART[$i] as $as_i) {
			if ($i !== $inp_K - 1) {
				print($as_i);
				$cou++;
				if ($cou != $count) {
					print(" ");
				} else {
					print("\n");
				}
			} else {
				print($as_i);
				$c++;
				if ($c != $count) {
					print(" ");
				}
			}
		}
	}
	$Scanner->close();
}

ob_end_clean();
solve();

//error_reporting(0);
//$Scanner = new Scanner("php://stdin");
class Scanner{
	private $Stream;
	private $Scanners = array();
	private $Id = 0;

	public function __construct($opend){
		if((!is_file($opend) && !is_link($opend)) && $opend !== "php://stdin"){
  			print("file or link or ''php://stdin' err");
  			exit;
		}

		$this->Stream = fopen($opend, 'r');
		$contents = stream_get_contents($this->Stream);

		//err $c_row = array("\n", "\r", "\r\n");
		$c_row = array("\r\n", "\r", "\n");
		$contents = str_replace($c_row, " ", $contents);
		$this->Scanners = explode(" ", $contents);
	}

	function Scan(){
		$x = $this->Id;
		$sc = $this->Scanners[$x];
		$this->Id = ++$x;
		return $sc;
	}

	function close(){
		fclose($this->Stream);
	}
}

/*
====begin=====

//input    $inp_ or upper
//block    $temp_
//two block$ttemp_
//as 	   $as_
//instance $(Upper)
//ref      $ref
//class menba $^Upper

====end=======

===== class begin =====

//error_reporting(0);
//$Scanner = new Scanner("php://stdin");
//ref "#109_div2_B_1230942 laurenceHR"
class LineScanner{
	private $Stream;
	private $Scanners = array();
	private $LineIds_Of_ScanIds= array();
	private $LinesScanners = array();
	private $LastScanIds_Of_LineIds = array();
	private $Scan_number = 0;
	private $Scanline_number = 0;

	public function __construct($opend){
		if((!is_file($opend) && !is_link($opend)) && $opend !== "php://stdin"){
  			print("file or link err");
  			exit;
		}

		$this->Stream = fopen($opend, 'r');
		$contents = stream_get_contents($this->Stream);

		$temp_lines = explode("\n", $contents);
		$temp_linescanners = array();
		$temp_x = 0;
		$temp_y = 0;
		//--attention for initting of array--(these is not needed but for easily reading)//
		$ttemp_scanners = array();
		//$del = Array("\n","\r","\n\r");
		foreach ($temp_lines as $as_line) {
			if (strlen($as_line) === 0) {
				print("input err");
			}

			//$as_line = str_replace($del,'',$as_line);
			$temp_linescanners[] = $as_line;
			$ttemp_line_scanners = explode(" ", $as_line);
			//$ttemp_scanners = array();
			foreach ($ttemp_line_scanners as $as_sc) {
				$ttemp_scanners[] = $as_sc;
				$this->LineIds_Of_ScanIds[$temp_x] = $temp_y;
				$temp_x++;
			}
			$this->LastScanIds_Of_LineIds[$temp_y] = $temp_x - 1;
			$temp_y++;
		}
		$this->Scanners = $ttemp_scanners;
		$this->LinesScanners = $temp_linescanners;
	}

	function Scan(){
		$x = $this->Scan_number;
		$y = $this->Scanline_number;
		if ($this->LineIds_Of_ScanIds[$x] === false || $this->LastScanIds_Of_LineIds[$y] === false) {
			print("scan err");
		}

		$sc = $this->Scanners[$x];
		//--attention for ++$x//
		//$this->Scan_number = $x++;
		$this->Scan_number = ++$x;
		$this->Scanline_number = $this->LineIds_Of_ScanIds[$x];
		return $sc;
	}

	function LineScan(){
		$x = $this->Scan_number;
		$y = $this->Scanline_number;
		if ($this->LineIds_Of_ScanIds[$x] === false || $this->LastScanIds_Of_LineIds[$y] === false) {
			print("linescan err");
		}

		$lsc = $this->LinesScanners[$y];
		$this->Scan_number = $this->LastScanIds_Of_LineIds[$y] + 1;
		$this->Scanline_number = $y + 1;
		return $lsc;
	}

	function close(){
		fclose($this->Stream);
	}
}

class Token{
	private $token;
	private $tok;

	public function __construct($str_line, $tok) {
		$this->tok = $tok;
		$this->token = strtok($str_line, $this->tok);
	}

	public function nextToken() {
		$thisToken = $this->token;
		$this->token = strtok($this->tok);
		return $thisToken;
	}

	public function nextFloat() {
		return (float)$this->nextToken();
	}

  	public function nextInt() {
		return (int)$this->nextToken();
	}

	public function nextIntArray() {
		$temp_arr = array();
		$flag = -1;
		while ($flag !== 1) {
			$thisToken = $this->nextToken();
			if ($thisToken !== false) {
				$temp_arr[] = $thisToken;
			} else {
				$flag = 1;
			}
		}
		return $temp_arr;
	}

	public function nnextIntArray($num) {
		$temp_arr = array();
		for ($i = 0; $i < $num; $i++) {
			$temp_arr[] = (int)$this->token;
		}
		return $temp_arr;
	}
}
===== class end ======

=== function begin ===

function get_line() {
        $stdin = fopen("php://stdin", "r");
        $line = rtrim($stdin, "\n");
        fclose($stdin);
        return $line;
}

function num_printf($i){
	if (is_float($i)) {
		printf("%.0f", $i);
	}
	if (is_int($i)) {
		printf("%d", $i);
	}
}

function array_printf(array $array) {
		$message = "";
		foreach ($array as $value) {
			$message .= "$value" . " ";
		}
		$message = rtrim($message);
		printf('%s', $message);
}

== function end ======
*/

?>

<?php
error_reporting(0);

function solve(){
	$Scanner = new Scanner("php://stdin");
	//$Scanner = new Scanner("input.txt");

	$inp_N = (int)$Scanner->Scan();
	$inp_K = (int)$Scanner->Scan();

	for ($i = 0; $i < $inp_N; $i++) {
		 $PRICE = $Scanner->Scan();
		 $TYPE = (int)$Scanner->Scan();
		 if ($TYPE === 1) $STOOLS[$i + 1] = $PRICE;
		 else if ($TYPE === 2) $PENCILS[$i + 1] = $PRICE;
	}

	if (!asort($STOOLS)) print("err");

	$min = 0;
	$sum = 0;
	$num = 0;
	$diff = count($STOOLS) - $inp_K;
	if ($diff >= 0) {
		foreach ($STOOLS as $STOOLS_key => $STOOLS_val) {
			if ($num <= $diff) {
				if ($num === 0) $min = $STOOLS_val / 2;
				$KART[0][] = $STOOLS_key;
			} else {
				$sum += $STOOLS_val / 2;
				$KART[$num - $diff][] = $STOOLS_key;
			}
			$num++;
		}

		$PEN_FLAG = 0;
		foreach ($PENCILS as $PENCILS_key => $PENCILS_val) {
			if ($PEN_FLAG === 0) {
				//$min = min($min, $PENCILS_val / 2) + ;
				if ($min > $PENCILS_val / 2) $min = $PENCILS_val / 2 + 2 * $min;
				elseif ($min <= $PENCILS_val / 2) $min = $PENCILS_val + $min;
				$PEN_FLAG = 1;
			}
			$KART[0][] = $PENCILS_key;
		}
		$sum = $sum + $min;
	} elseif($diff < 0)	{
		foreach ($STOOLS as $STOOLS_key => $STOOLS_val) {
			$sum += $STOOLS_val / 2;
			$KART[$num][] = $STOOLS_key;
			$num++;
		}

		foreach ($PENCILS as $PENCILS_key => $PENCILS_val) {
			if ($diff !== 0) {
				$sum += $PENCILS_val;
				$KART[$num][] = $PENCILS_key;
				$diff++;
				$num++;
			} else {
				$sum += $PENCILS_val;
				$KART[$inp_K - 1][] = $PENCILS_key;
			}
		}
	}
	printf("%.1f", $sum);
	print("\n");
	for ($i = 0; $i < $inp_K; $i++) {
		$count = count($KART[$i]);
		//print($sum);
		print($count);
		print(" ");
		$cou = 0;
		$c = 0;
		foreach ($KART[$i] as $as_i) {
			if ($i !== $inp_K - 1) {
				print($as_i);
				$cou++;
				//if ($cou != $count - 1) {
				if ($cou != $count) {
					print(" ");
				} else {
					print("\n");
				}
			} else {
				print($as_i);
				$c++;
				//if ($c != $count - 1) {
				if ($c != $count) {
					print(" ");
				}
			}
		}
	}
	$Scanner->close();
}

ob_end_clean();
solve();

//error_reporting(0);
//$Scanner = new Scanner("php://stdin");
class Scanner{
	private $Stream;
	private $Scanners = array();
	private $Id = 0;

	public function __construct($opend){
		if((!is_file($opend) && !is_link($opend)) && $opend !== "php://stdin"){
  			print("file or link or ''php://stdin' err");
  			exit;
		}

		$this->Stream = fopen($opend, 'r');
		$contents = stream_get_contents($this->Stream);

		//err $c_row = array("\n", "\r", "\r\n");
		$c_row = array("\r\n", "\r", "\n");
		$contents = str_replace($c_row, " ", $contents);
		$this->Scanners = explode(" ", $contents);
	}

	function Scan(){
		$x = $this->Id;
		$sc = $this->Scanners[$x];
		$this->Id = ++$x;
		return $sc;
	}

	function close(){
		fclose($this->Stream);
	}
}

/*
====begin=====

//input    $inp_ or upper
//block    $temp_
//two block$ttemp_
//as 	   $as_
//instance $(Upper)
//ref      $ref
//class menba $^Upper

====end=======

===== class begin =====

//error_reporting(0);
//$Scanner = new Scanner("php://stdin");
//ref "#109_div2_B_1230942 laurenceHR"
class LineScanner{
	private $Stream;
	private $Scanners = array();
	private $LineIds_Of_ScanIds= array();
	private $LinesScanners = array();
	private $LastScanIds_Of_LineIds = array();
	private $Scan_number = 0;
	private $Scanline_number = 0;

	public function __construct($opend){
		if((!is_file($opend) && !is_link($opend)) && $opend !== "php://stdin"){
  			print("file or link err");
  			exit;
		}

		$this->Stream = fopen($opend, 'r');
		$contents = stream_get_contents($this->Stream);

		$temp_lines = explode("\n", $contents);
		$temp_linescanners = array();
		$temp_x = 0;
		$temp_y = 0;
		//--attention for initting of array--(these is not needed but for easily reading)//
		$ttemp_scanners = array();
		//$del = Array("\n","\r","\n\r");
		foreach ($temp_lines as $as_line) {
			if (strlen($as_line) === 0) {
				print("input err");
			}

			//$as_line = str_replace($del,'',$as_line);
			$temp_linescanners[] = $as_line;
			$ttemp_line_scanners = explode(" ", $as_line);
			//$ttemp_scanners = array();
			foreach ($ttemp_line_scanners as $as_sc) {
				$ttemp_scanners[] = $as_sc;
				$this->LineIds_Of_ScanIds[$temp_x] = $temp_y;
				$temp_x++;
			}
			$this->LastScanIds_Of_LineIds[$temp_y] = $temp_x - 1;
			$temp_y++;
		}
		$this->Scanners = $ttemp_scanners;
		$this->LinesScanners = $temp_linescanners;
	}

	function Scan(){
		$x = $this->Scan_number;
		$y = $this->Scanline_number;
		if ($this->LineIds_Of_ScanIds[$x] === false || $this->LastScanIds_Of_LineIds[$y] === false) {
			print("scan err");
		}

		$sc = $this->Scanners[$x];
		//--attention for ++$x//
		//$this->Scan_number = $x++;
		$this->Scan_number = ++$x;
		$this->Scanline_number = $this->LineIds_Of_ScanIds[$x];
		return $sc;
	}

	function LineScan(){
		$x = $this->Scan_number;
		$y = $this->Scanline_number;
		if ($this->LineIds_Of_ScanIds[$x] === false || $this->LastScanIds_Of_LineIds[$y] === false) {
			print("linescan err");
		}

		$lsc = $this->LinesScanners[$y];
		$this->Scan_number = $this->LastScanIds_Of_LineIds[$y] + 1;
		$this->Scanline_number = $y + 1;
		return $lsc;
	}

	function close(){
		fclose($this->Stream);
	}
}

class Token{
	private $token;
	private $tok;

	public function __construct($str_line, $tok) {
		$this->tok = $tok;
		$this->token = strtok($str_line, $this->tok);
	}

	public function nextToken() {
		$thisToken = $this->token;
		$this->token = strtok($this->tok);
		return $thisToken;
	}

	public function nextFloat() {
		return (float)$this->nextToken();
	}

  	public function nextInt() {
		return (int)$this->nextToken();
	}

	public function nextIntArray() {
		$temp_arr = array();
		$flag = -1;
		while ($flag !== 1) {
			$thisToken = $this->nextToken();
			if ($thisToken !== false) {
				$temp_arr[] = $thisToken;
			} else {
				$flag = 1;
			}
		}
		return $temp_arr;
	}

	public function nnextIntArray($num) {
		$temp_arr = array();
		for ($i = 0; $i < $num; $i++) {
			$temp_arr[] = (int)$this->token;
		}
		return $temp_arr;
	}
}
===== class end ======

=== function begin ===

function get_line() {
        $stdin = fopen("php://stdin", "r");
        $line = rtrim($stdin, "\n");
        fclose($stdin);
        return $line;
}

function num_printf($i){
	if (is_float($i)) {
		printf("%.0f", $i);
	}
	if (is_int($i)) {
		printf("%d", $i);
	}
}

function array_printf(array $array) {
		$message = "";
		foreach ($array as $value) {
			$message .= "$value" . " ";
		}
		$message = rtrim($message);
		printf('%s', $message);
}

== function end ======
*/

?>

<?php
//error_reporting(0);

class Item{
	private $index;
	private $type;
	private $price;

	public function __construct($index, $type, $price) {
		$this->index = $index;
		$this->type = $type;
		$this->price = $price;
	}

	public function getIndex() {
		return $this->index;
	}

	public function getPrice() {
		return $this->price;
	}

	public function getType() {
		return $this->type;
	}

/* static → private?
    static function cmp_obj($a, $b) {
        $a_t = $a->getType();
        $b_t = $b->getType();
        $a_p = $a->getType();
        $b_p = $b->getType();

        if ($a_t < $b_t) {
            return 1;
        } elseif ($a_t = $b_t) {
			if ($a_p > $b_p) {
				return 1;
			} elseif ($a_p = $b_p) {
				return 0;
			} elseif ($a_p < $b_p) {
				return -1;
			}
		}
	}
*/
}

function compare(Item $a_item , Item $b_item){
	//$a_t = $a->getType();
	//$b_t = $b->getType();
	//$a_p = $a->getPrice();
	//$b_p = $b->getPrice();
	$a_t = $a_item->getType();
	$b_t = $b_item->getType();
	$a_p = $a_item->getPrice();
	$b_p = $b_item->getPrice();

	if ($a_t < $b_t) {
		return -1;
	} elseif ($a_t > $b_t) {
		return 1;
	//} elseif ($a_t = $b_t) {
	} elseif ($a_t === $b_t) {
		if ($a_p > $b_p) {
			//return 1;
			return -1;
		//} elseif ($a_p = $b_p) {
		} elseif ($a_p === $b_p) {
			return 0;
		} elseif ($a_p < $b_p) {
			//return -1;
			return 1;
		}
	}
}

function solve(){
	$Scanner = new Scanner("php://stdin");
	//$Scanner = new Scanner("input.txt");

	$inp_N = (int)$Scanner->Scan();
	$inp_K = (int)$Scanner->Scan();

	for ($i = 0; $i < $inp_N; $i++) {
		$PRICE = $Scanner->Scan();
		$TYPE = (int)$Scanner->Scan();
		$ITEMS[] = new Item($i + 1, $TYPE, $PRICE);
	}

	//usort($ITEMS, array("ITEM", "compare"));
	usort($ITEMS, "compare");
	var_dump($ITEMS);

	for ($i = 0; $i < $inp_N; $i++) {
		if ($i < $inp_K - 1) {
			//$KART[$i] = $ITEMS[$i]->getIndex();
			$KART[$i][] = $ITEMS[$i]->getIndex();
		} elseif ($i >= $inp_K - 1) {
			$KART[$inp_K - 1][] = $ITEMS[$i]->getIndex();
		}
	}

	for ($i = 0; $i < $inp_N; $i++) {
		$type = $ITEMS[$i]->getType();
		if ($i < $inp_K - 1 && $type === 1) {
			$sum += $ITEMS[$i]->getPrice() / 2;
		} elseif ($i >= $inp_K - 1 || $type !== 1) {
			$sum += $ITEMS[$i]->getPrice();
		}
	}

	//$min = 1E9 + 1;
	if ($ITEMS[$inp_K - 1]->getType() === 1) {
		$min = 1E9 + 1;
		for ($i = $inp_K - 1; $i < $inp_N; $i++) {
			$temp = $ITEMS[$i]->getPrice();
			$min = min($temp, $min);
		}
	}
	$sum -= $min / 2;

	printf("%.1f", $sum);
	print("\n");
	for ($i = 0; $i < $inp_K; $i++) {
		$count = count($KART[$i]);
		//print($sum);
		print($count);
		print(" ");
		$cou = 0;
		$c = 0;
		foreach ($KART[$i] as $as_i) {
			if ($i !== $inp_K - 1) {
				print($as_i);
				$cou++;
				//if ($cou != $count - 1) {
				if ($cou != $count) {
					print(" ");
				} else {
					print("\n");
				}
			} else {
				print($as_i);
				$c++;
				//if ($c != $count - 1) {
				if ($c != $count) {
					print(" ");
				}
			}
		}
	}
	$Scanner->close();
}

ob_end_clean();
solve();

//error_reporting(0);
//$Scanner = new Scanner("php://stdin");
class Scanner{
	private $Stream;
	private $Scanners = array();
	private $Id = 0;

	public function __construct($opend){
		if((!is_file($opend) && !is_link($opend)) && $opend !== "php://stdin"){
  			print("file or link or ''php://stdin' err");
  			exit;
		}

		$this->Stream = fopen($opend, 'r');
		$contents = stream_get_contents($this->Stream);

		//err $c_row = array("\n", "\r", "\r\n");
		$c_row = array("\r\n", "\r", "\n");
		$contents = str_replace($c_row, " ", $contents);
		$this->Scanners = explode(" ", $contents);
	}

	function Scan(){
		$x = $this->Id;
		$sc = $this->Scanners[$x];
		$this->Id = ++$x;
		return $sc;
	}

	function close(){
		fclose($this->Stream);
	}
}

/*
====begin=====

//input    $inp_ or upper
//block    $temp_
//two block$ttemp_
//as 	   $as_
//instance $(Upper)
//ref      $ref
//class menba $^Upper

====end=======

===== class begin =====

//error_reporting(0);
//$Scanner = new Scanner("php://stdin");
//ref "#109_div2_B_1230942 laurenceHR"
class LineScanner{
	private $Stream;
	private $Scanners = array();
	private $LineIds_Of_ScanIds= array();
	private $LinesScanners = array();
	private $LastScanIds_Of_LineIds = array();
	private $Scan_number = 0;
	private $Scanline_number = 0;

	public function __construct($opend){
		if((!is_file($opend) && !is_link($opend)) && $opend !== "php://stdin"){
  			print("file or link err");
  			exit;
		}

		$this->Stream = fopen($opend, 'r');
		$contents = stream_get_contents($this->Stream);

		$temp_lines = explode("\n", $contents);
		$temp_linescanners = array();
		$temp_x = 0;
		$temp_y = 0;
		//--attention for initting of array--(these is not needed but for easily reading)//
		$ttemp_scanners = array();
		//$del = Array("\n","\r","\n\r");
		foreach ($temp_lines as $as_line) {
			if (strlen($as_line) === 0) {
				print("input err");
			}

			//$as_line = str_replace($del,'',$as_line);
			$temp_linescanners[] = $as_line;
			$ttemp_line_scanners = explode(" ", $as_line);
			//$ttemp_scanners = array();
			foreach ($ttemp_line_scanners as $as_sc) {
				$ttemp_scanners[] = $as_sc;
				$this->LineIds_Of_ScanIds[$temp_x] = $temp_y;
				$temp_x++;
			}
			$this->LastScanIds_Of_LineIds[$temp_y] = $temp_x - 1;
			$temp_y++;
		}
		$this->Scanners = $ttemp_scanners;
		$this->LinesScanners = $temp_linescanners;
	}

	function Scan(){
		$x = $this->Scan_number;
		$y = $this->Scanline_number;
		if ($this->LineIds_Of_ScanIds[$x] === false || $this->LastScanIds_Of_LineIds[$y] === false) {
			print("scan err");
		}

		$sc = $this->Scanners[$x];
		//--attention for ++$x//
		//$this->Scan_number = $x++;
		$this->Scan_number = ++$x;
		$this->Scanline_number = $this->LineIds_Of_ScanIds[$x];
		return $sc;
	}

	function LineScan(){
		$x = $this->Scan_number;
		$y = $this->Scanline_number;
		if ($this->LineIds_Of_ScanIds[$x] === false || $this->LastScanIds_Of_LineIds[$y] === false) {
			print("linescan err");
		}

		$lsc = $this->LinesScanners[$y];
		$this->Scan_number = $this->LastScanIds_Of_LineIds[$y] + 1;
		$this->Scanline_number = $y + 1;
		return $lsc;
	}

	function close(){
		fclose($this->Stream);
	}
}

class Token{
	private $token;
	private $tok;

	public function __construct($str_line, $tok) {
		$this->tok = $tok;
		$this->token = strtok($str_line, $this->tok);
	}

	public function nextToken() {
		$thisToken = $this->token;
		$this->token = strtok($this->tok);
		return $thisToken;
	}

	public function nextFloat() {
		return (float)$this->nextToken();
	}

  	public function nextInt() {
		return (int)$this->nextToken();
	}

	public function nextIntArray() {
		$temp_arr = array();
		$flag = -1;
		while ($flag !== 1) {
			$thisToken = $this->nextToken();
			if ($thisToken !== false) {
				$temp_arr[] = $thisToken;
			} else {
				$flag = 1;
			}
		}
		return $temp_arr;
	}

	public function nnextIntArray($num) {
		$temp_arr = array();
		for ($i = 0; $i < $num; $i++) {
			$temp_arr[] = (int)$this->token;
		}
		return $temp_arr;
	}
}
===== class end ======

=== function begin ===

function get_line() {
        $stdin = fopen("php://stdin", "r");
        $line = rtrim($stdin, "\n");
        fclose($stdin);
        return $line;
}

function num_printf($i){
	if (is_float($i)) {
		printf("%.0f", $i);
	}
	if (is_int($i)) {
		printf("%d", $i);
	}
}

function array_printf(array $array) {
		$message = "";
		foreach ($array as $value) {
			$message .= "$value" . " ";
		}
		$message = rtrim($message);
		printf('%s', $message);
}

== function end ======
*/

?>

<?php
//error_reporting(0);

class Item{
	private $index;
	private $type;
	private $price;

	public function __construct($index, $type, $price) {
		$this->index = $index;
		$this->type = $type;
		$this->price = $price;
	}

	public function getIndex() {
		return $this->index;
	}

	public function getPrice() {
		return $this->price;
	}

	public function getType() {
		return $this->type;
	}

    static function compareItem($a_item, $b_item) {
		$a_t = $a_item->getType();
		$b_t = $b_item->getType();
		$a_p = $a_item->getPrice();
		$b_p = $b_item->getPrice();

		if ($a_t < $b_t) return -1;
		elseif ($a_t > $b_t) return 1;
		elseif ($a_t === $b_t) {
			if ($a_p > $b_p) return -1;
			elseif ($a_p === $b_p) return 0;
			elseif ($a_p < $b_p) return 1;
		}
	}
}
/*
function compare(Item $a_item , Item $b_item){
	//$a_t = $a->getType();
	//$b_t = $b->getType();
	//$a_p = $a->getPrice();
	//$b_p = $b->getPrice();
	$a_t = $a_item->getType();
	$b_t = $b_item->getType();
	$a_p = $a_item->getPrice();
	$b_p = $b_item->getPrice();

	if ($a_t < $b_t) {
		return -1;
	} elseif ($a_t > $b_t) {
		return 1;
	//} elseif ($a_t = $b_t) {
	} elseif ($a_t === $b_t) {
		if ($a_p > $b_p) {
			//return 1;
			return -1;
		//} elseif ($a_p = $b_p) {
		} elseif ($a_p === $b_p) {
			return 0;
		} elseif ($a_p < $b_p) {
			//return -1;
			return 1;
		}
	}
}
*/
function solve(){
	$Scanner = new Scanner("php://stdin");
	//$Scanner = new Scanner("input.txt");

	$inp_N = (int)$Scanner->Scan();
	$inp_K = (int)$Scanner->Scan();

	for ($i = 0; $i < $inp_N; $i++) {
		$PRICE = $Scanner->Scan();
		$TYPE = (int)$Scanner->Scan();
		$ITEMS[] = new Item($i + 1, $TYPE, $PRICE);
	}

	usort($ITEMS, array("Item", "compare"));
	//usort($ITEMS, "compare");
	for ($i = 0; $i < $inp_N; $i++) {
		if ($i < $inp_K - 1) {
			//$KART[$i] = $ITEMS[$i]->getIndex();
			$KART[$i][] = $ITEMS[$i]->getIndex();
		} elseif ($i >= $inp_K - 1) {
			$KART[$inp_K - 1][] = $ITEMS[$i]->getIndex();
		}
	}

	for ($i = 0; $i < $inp_N; $i++) {
		$type = $ITEMS[$i]->getType();
		if ($i < $inp_K - 1 && $type === 1) {
			$sum += $ITEMS[$i]->getPrice() / 2;
		} elseif ($i >= $inp_K - 1 || $type !== 1) {
			$sum += $ITEMS[$i]->getPrice();
		}
	}

	//$min = 1E9 + 1;
	if ($ITEMS[$inp_K - 1]->getType() === 1) {
		$min = 1E9 + 1;
		for ($i = $inp_K - 1; $i < $inp_N; $i++) {
			$temp = $ITEMS[$i]->getPrice();
			$min = min($temp, $min);
		}
	}
	$sum -= $min / 2;

	printf("%.1f", $sum);
	print("\n");
	for ($i = 0; $i < $inp_K; $i++) {
		$count = count($KART[$i]);
		//print($sum);
		print($count);
		print(" ");
		$cou = 0;
		$c = 0;
		foreach ($KART[$i] as $as_i) {
			if ($i !== $inp_K - 1) {
				print($as_i);
				$cou++;
				//if ($cou != $count - 1) {
				if ($cou != $count) {
					print(" ");
				} else {
					print("\n");
				}
			} else {
				print($as_i);
				$c++;
				//if ($c != $count - 1) {
				if ($c != $count) {
					print(" ");
				}
			}
		}
	}
	$Scanner->close();
}

ob_end_clean();
solve();

//error_reporting(0);
//$Scanner = new Scanner("php://stdin");
class Scanner{
	private $Stream;
	private $Scanners = array();
	private $Id = 0;

	public function __construct($opend){
		if((!is_file($opend) && !is_link($opend)) && $opend !== "php://stdin"){
  			print("file or link or ''php://stdin' err");
  			exit;
		}

		$this->Stream = fopen($opend, 'r');
		$contents = stream_get_contents($this->Stream);

		//err $c_row = array("\n", "\r", "\r\n");
		$c_row = array("\r\n", "\r", "\n");
		$contents = str_replace($c_row, " ", $contents);
		$this->Scanners = explode(" ", $contents);
	}

	function Scan(){
		$x = $this->Id;
		$sc = $this->Scanners[$x];
		$this->Id = ++$x;
		return $sc;
	}

	function close(){
		fclose($this->Stream);
	}
}

/*
====begin=====

//input    $inp_ or upper
//block    $temp_
//two block$ttemp_
//as 	   $as_
//instance $(Upper)
//ref      $ref
//class menba $^Upper

====end=======

===== class begin =====

//error_reporting(0);
//$Scanner = new Scanner("php://stdin");
//ref "#109_div2_B_1230942 laurenceHR"
class LineScanner{
	private $Stream;
	private $Scanners = array();
	private $LineIds_Of_ScanIds= array();
	private $LinesScanners = array();
	private $LastScanIds_Of_LineIds = array();
	private $Scan_number = 0;
	private $Scanline_number = 0;

	public function __construct($opend){
		if((!is_file($opend) && !is_link($opend)) && $opend !== "php://stdin"){
  			print("file or link err");
  			exit;
		}

		$this->Stream = fopen($opend, 'r');
		$contents = stream_get_contents($this->Stream);

		$temp_lines = explode("\n", $contents);
		$temp_linescanners = array();
		$temp_x = 0;
		$temp_y = 0;
		//--attention for initting of array--(these is not needed but for easily reading)//
		$ttemp_scanners = array();
		//$del = Array("\n","\r","\n\r");
		foreach ($temp_lines as $as_line) {
			if (strlen($as_line) === 0) {
				print("input err");
			}

			//$as_line = str_replace($del,'',$as_line);
			$temp_linescanners[] = $as_line;
			$ttemp_line_scanners = explode(" ", $as_line);
			//$ttemp_scanners = array();
			foreach ($ttemp_line_scanners as $as_sc) {
				$ttemp_scanners[] = $as_sc;
				$this->LineIds_Of_ScanIds[$temp_x] = $temp_y;
				$temp_x++;
			}
			$this->LastScanIds_Of_LineIds[$temp_y] = $temp_x - 1;
			$temp_y++;
		}
		$this->Scanners = $ttemp_scanners;
		$this->LinesScanners = $temp_linescanners;
	}

	function Scan(){
		$x = $this->Scan_number;
		$y = $this->Scanline_number;
		if ($this->LineIds_Of_ScanIds[$x] === false || $this->LastScanIds_Of_LineIds[$y] === false) {
			print("scan err");
		}

		$sc = $this->Scanners[$x];
		//--attention for ++$x//
		//$this->Scan_number = $x++;
		$this->Scan_number = ++$x;
		$this->Scanline_number = $this->LineIds_Of_ScanIds[$x];
		return $sc;
	}

	function LineScan(){
		$x = $this->Scan_number;
		$y = $this->Scanline_number;
		if ($this->LineIds_Of_ScanIds[$x] === false || $this->LastScanIds_Of_LineIds[$y] === false) {
			print("linescan err");
		}

		$lsc = $this->LinesScanners[$y];
		$this->Scan_number = $this->LastScanIds_Of_LineIds[$y] + 1;
		$this->Scanline_number = $y + 1;
		return $lsc;
	}

	function close(){
		fclose($this->Stream);
	}
}

class Token{
	private $token;
	private $tok;

	public function __construct($str_line, $tok) {
		$this->tok = $tok;
		$this->token = strtok($str_line, $this->tok);
	}

	public function nextToken() {
		$thisToken = $this->token;
		$this->token = strtok($this->tok);
		return $thisToken;
	}

	public function nextFloat() {
		return (float)$this->nextToken();
	}

  	public function nextInt() {
		return (int)$this->nextToken();
	}

	public function nextIntArray() {
		$temp_arr = array();
		$flag = -1;
		while ($flag !== 1) {
			$thisToken = $this->nextToken();
			if ($thisToken !== false) {
				$temp_arr[] = $thisToken;
			} else {
				$flag = 1;
			}
		}
		return $temp_arr;
	}

	public function nnextIntArray($num) {
		$temp_arr = array();
		for ($i = 0; $i < $num; $i++) {
			$temp_arr[] = (int)$this->token;
		}
		return $temp_arr;
	}
}
===== class end ======

=== function begin ===

function get_line() {
        $stdin = fopen("php://stdin", "r");
        $line = rtrim($stdin, "\n");
        fclose($stdin);
        return $line;
}

function num_printf($i){
	if (is_float($i)) {
		printf("%.0f", $i);
	}
	if (is_int($i)) {
		printf("%d", $i);
	}
}

function array_printf(array $array) {
		$message = "";
		foreach ($array as $value) {
			$message .= "$value" . " ";
		}
		$message = rtrim($message);
		printf('%s', $message);
}

== function end ======
*/

?>

<?php
error_reporting(0);

function solve(){
	$Scanner = new Scanner("php://stdin");
	//$Scanner = new Scanner("input.txt");

	$inp_N = (int)$Scanner->Scan();
	$inp_K = (int)$Scanner->Scan();

	for ($i = 0; $i < $inp_N; $i++) {
		 $PRICE = $Scanner->Scan();
		 $TYPE = (int)$Scanner->Scan();
		 if ($TYPE === 1) $STOOLS[$i + 1] = $PRICE;
		 else if ($TYPE === 2) $PENCILS[$i + 1] = $PRICE;
	}

	//if (!asort($STOOLS)) print("err");
	//In case $STOOLS is null, this is printed;

	asort($STOOLS);
	$min = 0;
	$sum = 0;
	$num = 0;
	$diff = count($STOOLS) - $inp_K;
	if ($diff >= 0) {
		foreach ($STOOLS as $STOOLS_key => $STOOLS_val) {
			if ($num <= $diff) {
				if ($num === 0) $min = $STOOLS_val / 2;
				else $sum += $STOOLS_val;
				$KART[0][] = $STOOLS_key;
			} else {
				$sum += $STOOLS_val / 2;
				$KART[$num - $diff][] = $STOOLS_key;
			}
			$num++;
		}

		$PEN_FLAG = 0;
		foreach ($PENCILS as $PENCILS_key => $PENCILS_val) {
			if ($PEN_FLAG === 0) {
				//$min = min($min, $PENCILS_val / 2) + ;
				if ($min > $PENCILS_val / 2) $min = $PENCILS_val / 2 + 2 * $min;
				elseif ($min <= $PENCILS_val / 2) $min = $PENCILS_val + $min;
				$PEN_FLAG = 1;
			} else {
				$sum += $PENCILS_val;
			}
			$KART[0][] = $PENCILS_key;
		}
		$sum = $sum + $min;
	} elseif($diff < 0)	{
		foreach ($STOOLS as $STOOLS_key => $STOOLS_val) {
			$sum += $STOOLS_val / 2;
			$KART[$num][] = $STOOLS_key;
			$num++;
		}

		foreach ($PENCILS as $PENCILS_key => $PENCILS_val) {
			if ($diff !== 0) {
				$sum += $PENCILS_val;
				$KART[$num][] = $PENCILS_key;
				$diff++;
				$num++;
			} else {
				$sum += $PENCILS_val;
				$KART[$inp_K - 1][] = $PENCILS_key;
			}
		}
	}
	printf("%.1f", $sum);
	print("\n");
	for ($i = 0; $i < $inp_K; $i++) {
		$count = count($KART[$i]);
		//print($sum);
		print($count);
		print(" ");
		$cou = 0;
		$c = 0;
		foreach ($KART[$i] as $as_i) {
			if ($i !== $inp_K - 1) {
				print($as_i);
				$cou++;
				//if ($cou != $count - 1) {
				if ($cou != $count) {
					print(" ");
				} else {
					print("\n");
				}
			} else {
				print($as_i);
				$c++;
				//if ($c != $count - 1) {
				if ($c != $count) {
					print(" ");
				}
			}
		}
	}
	$Scanner->close();
}

ob_end_clean();
solve();

//error_reporting(0);
//$Scanner = new Scanner("php://stdin");
class Scanner{
	private $Stream;
	private $Scanners = array();
	private $Id = 0;

	public function __construct($opend){
		if((!is_file($opend) && !is_link($opend)) && $opend !== "php://stdin"){
  			print("file or link or ''php://stdin' err");
  			exit;
		}

		$this->Stream = fopen($opend, 'r');
		$contents = stream_get_contents($this->Stream);

		//err $c_row = array("\n", "\r", "\r\n");
		$c_row = array("\r\n", "\r", "\n");
		$contents = str_replace($c_row, " ", $contents);
		$this->Scanners = explode(" ", $contents);
	}

	function Scan(){
		$x = $this->Id;
		$sc = $this->Scanners[$x];
		$this->Id = ++$x;
		return $sc;
	}

	function close(){
		fclose($this->Stream);
	}
}

/*
====begin=====

//input    $inp_ or upper
//block    $temp_
//two block$ttemp_
//as 	   $as_
//instance $(Upper)
//ref      $ref
//class menba $^Upper

====end=======

===== class begin =====

//error_reporting(0);
//$Scanner = new Scanner("php://stdin");
//ref "#109_div2_B_1230942 laurenceHR"
class LineScanner{
	private $Stream;
	private $Scanners = array();
	private $LineIds_Of_ScanIds= array();
	private $LinesScanners = array();
	private $LastScanIds_Of_LineIds = array();
	private $Scan_number = 0;
	private $Scanline_number = 0;

	public function __construct($opend){
		if((!is_file($opend) && !is_link($opend)) && $opend !== "php://stdin"){
  			print("file or link err");
  			exit;
		}

		$this->Stream = fopen($opend, 'r');
		$contents = stream_get_contents($this->Stream);

		$temp_lines = explode("\n", $contents);
		$temp_linescanners = array();
		$temp_x = 0;
		$temp_y = 0;
		//--attention for initting of array--(these is not needed but for easily reading)//
		$ttemp_scanners = array();
		//$del = Array("\n","\r","\n\r");
		foreach ($temp_lines as $as_line) {
			if (strlen($as_line) === 0) {
				print("input err");
			}

			//$as_line = str_replace($del,'',$as_line);
			$temp_linescanners[] = $as_line;
			$ttemp_line_scanners = explode(" ", $as_line);
			//$ttemp_scanners = array();
			foreach ($ttemp_line_scanners as $as_sc) {
				$ttemp_scanners[] = $as_sc;
				$this->LineIds_Of_ScanIds[$temp_x] = $temp_y;
				$temp_x++;
			}
			$this->LastScanIds_Of_LineIds[$temp_y] = $temp_x - 1;
			$temp_y++;
		}
		$this->Scanners = $ttemp_scanners;
		$this->LinesScanners = $temp_linescanners;
	}

	function Scan(){
		$x = $this->Scan_number;
		$y = $this->Scanline_number;
		if ($this->LineIds_Of_ScanIds[$x] === false || $this->LastScanIds_Of_LineIds[$y] === false) {
			print("scan err");
		}

		$sc = $this->Scanners[$x];
		//--attention for ++$x//
		//$this->Scan_number = $x++;
		$this->Scan_number = ++$x;
		$this->Scanline_number = $this->LineIds_Of_ScanIds[$x];
		return $sc;
	}

	function LineScan(){
		$x = $this->Scan_number;
		$y = $this->Scanline_number;
		if ($this->LineIds_Of_ScanIds[$x] === false || $this->LastScanIds_Of_LineIds[$y] === false) {
			print("linescan err");
		}

		$lsc = $this->LinesScanners[$y];
		$this->Scan_number = $this->LastScanIds_Of_LineIds[$y] + 1;
		$this->Scanline_number = $y + 1;
		return $lsc;
	}

	function close(){
		fclose($this->Stream);
	}
}

class Token{
	private $token;
	private $tok;

	public function __construct($str_line, $tok) {
		$this->tok = $tok;
		$this->token = strtok($str_line, $this->tok);
	}

	public function nextToken() {
		$thisToken = $this->token;
		$this->token = strtok($this->tok);
		return $thisToken;
	}

	public function nextFloat() {
		return (float)$this->nextToken();
	}

  	public function nextInt() {
		return (int)$this->nextToken();
	}

	public function nextIntArray() {
		$temp_arr = array();
		$flag = -1;
		while ($flag !== 1) {
			$thisToken = $this->nextToken();
			if ($thisToken !== false) {
				$temp_arr[] = $thisToken;
			} else {
				$flag = 1;
			}
		}
		return $temp_arr;
	}

	public function nnextIntArray($num) {
		$temp_arr = array();
		for ($i = 0; $i < $num; $i++) {
			$temp_arr[] = (int)$this->token;
		}
		return $temp_arr;
	}
}
===== class end ======

=== function begin ===

function get_line() {
        $stdin = fopen("php://stdin", "r");
        $line = rtrim($stdin, "\n");
        fclose($stdin);
        return $line;
}

function num_printf($i){
	if (is_float($i)) {
		printf("%.0f", $i);
	}
	if (is_int($i)) {
		printf("%d", $i);
	}
}

function array_printf(array $array) {
		$message = "";
		foreach ($array as $value) {
			$message .= "$value" . " ";
		}
		$message = rtrim($message);
		printf('%s', $message);
}

== function end ======
*/

?>

<?php
//error_reporting(0);

class Item{
	private $index;
	private $type;
	private $price;

	public function __construct($index, $type, $price) {
		$this->index = $index;
		$this->type = $type;
		$this->price = $price;
	}

	public function getIndex() {
		return $this->index;
	}

	public function getPrice() {
		return $this->price;
	}

	public function getType() {
		return $this->type;
	}

    static function compareItem($a_item, $b_item) {
		$a_t = $a_item->getType();
		$b_t = $b_item->getType();
		$a_p = $a_item->getPrice();
		$b_p = $b_item->getPrice();

		if ($a_t < $b_t) return -1;
		elseif ($a_t > $b_t) return 1;
		elseif ($a_t === $b_t) {
			if ($a_p > $b_p) return -1;
			elseif ($a_p === $b_p) return 0;
			elseif ($a_p < $b_p) return 1;
		}
	}
}
/*
function compare(Item $a_item , Item $b_item){
	//$a_t = $a->getType();
	//$b_t = $b->getType();
	//$a_p = $a->getPrice();
	//$b_p = $b->getPrice();
	$a_t = $a_item->getType();
	$b_t = $b_item->getType();
	$a_p = $a_item->getPrice();
	$b_p = $b_item->getPrice();

	if ($a_t < $b_t) {
		return -1;
	} elseif ($a_t > $b_t) {
		return 1;
	//} elseif ($a_t = $b_t) {
	} elseif ($a_t === $b_t) {
		if ($a_p > $b_p) {
			//return 1;
			return -1;
		//} elseif ($a_p = $b_p) {
		} elseif ($a_p === $b_p) {
			return 0;
		} elseif ($a_p < $b_p) {
			//return -1;
			return 1;
		}
	}
}
*/
function solve(){
	$Scanner = new Scanner("php://stdin");
	//$Scanner = new Scanner("input.txt");

	$inp_N = (int)$Scanner->Scan();
	$inp_K = (int)$Scanner->Scan();

	for ($i = 0; $i < $inp_N; $i++) {
		$PRICE = $Scanner->Scan();
		$TYPE = (int)$Scanner->Scan();
		$ITEMS[] = new Item($i + 1, $TYPE, $PRICE);
	}

	//usort($ITEMS, array("ITEM", "compare"));
	usort($ITEMS, "compare");
	for ($i = 0; $i < $inp_N; $i++) {
		if ($i < $inp_K - 1) {
			//$KART[$i] = $ITEMS[$i]->getIndex();
			$KART[$i][] = $ITEMS[$i]->getIndex();
		} elseif ($i >= $inp_K - 1) {
			$KART[$inp_K - 1][] = $ITEMS[$i]->getIndex();
		}
	}

	for ($i = 0; $i < $inp_N; $i++) {
		$type = $ITEMS[$i]->getType();
		if ($i < $inp_K - 1 && $type === 1) {
			$sum += $ITEMS[$i]->getPrice() / 2;
		} elseif ($i >= $inp_K - 1 || $type !== 1) {
			$sum += $ITEMS[$i]->getPrice();
		}
	}

	//$min = 1E9 + 1;
	if ($ITEMS[$inp_K - 1]->getType() === 1) {
		$min = 1E9 + 1;
		for ($i = $inp_K - 1; $i < $inp_N; $i++) {
			$temp = $ITEMS[$i]->getPrice();
			$min = min($temp, $min);
		}
	}
	$sum -= $min / 2;

	printf("%.1f", $sum);
	print("\n");
	for ($i = 0; $i < $inp_K; $i++) {
		$count = count($KART[$i]);
		//print($sum);
		print($count);
		print(" ");
		$cou = 0;
		$c = 0;
		foreach ($KART[$i] as $as_i) {
			if ($i !== $inp_K - 1) {
				print($as_i);
				$cou++;
				//if ($cou != $count - 1) {
				if ($cou != $count) {
					print(" ");
				} else {
					print("\n");
				}
			} else {
				print($as_i);
				$c++;
				//if ($c != $count - 1) {
				if ($c != $count) {
					print(" ");
				}
			}
		}
	}
	$Scanner->close();
}

ob_end_clean();
solve();

//error_reporting(0);
//$Scanner = new Scanner("php://stdin");
class Scanner{
	private $Stream;
	private $Scanners = array();
	private $Id = 0;

	public function __construct($opend){
		if((!is_file($opend) && !is_link($opend)) && $opend !== "php://stdin"){
  			print("file or link or ''php://stdin' err");
  			exit;
		}

		$this->Stream = fopen($opend, 'r');
		$contents = stream_get_contents($this->Stream);

		//err $c_row = array("\n", "\r", "\r\n");
		$c_row = array("\r\n", "\r", "\n");
		$contents = str_replace($c_row, " ", $contents);
		$this->Scanners = explode(" ", $contents);
	}

	function Scan(){
		$x = $this->Id;
		$sc = $this->Scanners[$x];
		$this->Id = ++$x;
		return $sc;
	}

	function close(){
		fclose($this->Stream);
	}
}

/*
====begin=====

//input    $inp_ or upper
//block    $temp_
//two block$ttemp_
//as 	   $as_
//instance $(Upper)
//ref      $ref
//class menba $^Upper

====end=======

===== class begin =====

//error_reporting(0);
//$Scanner = new Scanner("php://stdin");
//ref "#109_div2_B_1230942 laurenceHR"
class LineScanner{
	private $Stream;
	private $Scanners = array();
	private $LineIds_Of_ScanIds= array();
	private $LinesScanners = array();
	private $LastScanIds_Of_LineIds = array();
	private $Scan_number = 0;
	private $Scanline_number = 0;

	public function __construct($opend){
		if((!is_file($opend) && !is_link($opend)) && $opend !== "php://stdin"){
  			print("file or link err");
  			exit;
		}

		$this->Stream = fopen($opend, 'r');
		$contents = stream_get_contents($this->Stream);

		$temp_lines = explode("\n", $contents);
		$temp_linescanners = array();
		$temp_x = 0;
		$temp_y = 0;
		//--attention for initting of array--(these is not needed but for easily reading)//
		$ttemp_scanners = array();
		//$del = Array("\n","\r","\n\r");
		foreach ($temp_lines as $as_line) {
			if (strlen($as_line) === 0) {
				print("input err");
			}

			//$as_line = str_replace($del,'',$as_line);
			$temp_linescanners[] = $as_line;
			$ttemp_line_scanners = explode(" ", $as_line);
			//$ttemp_scanners = array();
			foreach ($ttemp_line_scanners as $as_sc) {
				$ttemp_scanners[] = $as_sc;
				$this->LineIds_Of_ScanIds[$temp_x] = $temp_y;
				$temp_x++;
			}
			$this->LastScanIds_Of_LineIds[$temp_y] = $temp_x - 1;
			$temp_y++;
		}
		$this->Scanners = $ttemp_scanners;
		$this->LinesScanners = $temp_linescanners;
	}

	function Scan(){
		$x = $this->Scan_number;
		$y = $this->Scanline_number;
		if ($this->LineIds_Of_ScanIds[$x] === false || $this->LastScanIds_Of_LineIds[$y] === false) {
			print("scan err");
		}

		$sc = $this->Scanners[$x];
		//--attention for ++$x//
		//$this->Scan_number = $x++;
		$this->Scan_number = ++$x;
		$this->Scanline_number = $this->LineIds_Of_ScanIds[$x];
		return $sc;
	}

	function LineScan(){
		$x = $this->Scan_number;
		$y = $this->Scanline_number;
		if ($this->LineIds_Of_ScanIds[$x] === false || $this->LastScanIds_Of_LineIds[$y] === false) {
			print("linescan err");
		}

		$lsc = $this->LinesScanners[$y];
		$this->Scan_number = $this->LastScanIds_Of_LineIds[$y] + 1;
		$this->Scanline_number = $y + 1;
		return $lsc;
	}

	function close(){
		fclose($this->Stream);
	}
}

class Token{
	private $token;
	private $tok;

	public function __construct($str_line, $tok) {
		$this->tok = $tok;
		$this->token = strtok($str_line, $this->tok);
	}

	public function nextToken() {
		$thisToken = $this->token;
		$this->token = strtok($this->tok);
		return $thisToken;
	}

	public function nextFloat() {
		return (float)$this->nextToken();
	}

  	public function nextInt() {
		return (int)$this->nextToken();
	}

	public function nextIntArray() {
		$temp_arr = array();
		$flag = -1;
		while ($flag !== 1) {
			$thisToken = $this->nextToken();
			if ($thisToken !== false) {
				$temp_arr[] = $thisToken;
			} else {
				$flag = 1;
			}
		}
		return $temp_arr;
	}

	public function nnextIntArray($num) {
		$temp_arr = array();
		for ($i = 0; $i < $num; $i++) {
			$temp_arr[] = (int)$this->token;
		}
		return $temp_arr;
	}
}
===== class end ======

=== function begin ===

function get_line() {
        $stdin = fopen("php://stdin", "r");
        $line = rtrim($stdin, "\n");
        fclose($stdin);
        return $line;
}

function num_printf($i){
	if (is_float($i)) {
		printf("%.0f", $i);
	}
	if (is_int($i)) {
		printf("%d", $i);
	}
}

function array_printf(array $array) {
		$message = "";
		foreach ($array as $value) {
			$message .= "$value" . " ";
		}
		$message = rtrim($message);
		printf('%s', $message);
}

== function end ======
*/

?>

<?php
error_reporting(0);

function solve(){
	$Scanner = new Scanner("php://stdin");
	//$Scanner = new Scanner("input.txt");

	$inp_N = (int)$Scanner->Scan();
	$inp_K = (int)$Scanner->Scan();

	for ($i = 0; $i < $inp_N; $i++) {
		$PRICE = $Scanner->Scan();
		$TYPE = (int)$Scanner->Scan();
		if ($TYPE === 1) $ITEMS[$i][] = $TYPE + 2;
		else $ITEMS[$i][] = $TYPE;
		$ITEMS[$i][] = $PRICE;
	}

	arsort($ITEMS);
	$keys = array_keys($ITEMS);
	for ($i = 0; $i < $inp_N; $i++) {
		if ($i < $inp_K - 1) {
			$KART[$i][] = $keys[$i] + 1;
		} elseif ($i >= $inp_K - 1) {
			$KART[$inp_K - 1][] = $keys[$i] + 1;
		}
	}

	for ($i = 0; $i < $inp_N; $i++) {
		$type = $ITEMS[$i][0];
		if ($i < $inp_K - 1 && $type === 3) {
			$sum += $ITEMS[$i][1] / 2;
		} elseif ($i >= $inp_K - 1 || $type !== 3) {
			$sum += $ITEMS[$i][1];
		}
	}

	//if ($ITEMS[$inp_K - 1][0] === 3) {
	if ($ITEMS[$keys[$inp_K - 1]][0] === 3) {
		$min = 1E9 + 1;
		for ($i = $inp_K - 1; $i < $inp_N; $i++) {
			$temp = $ITEMS[$i][1];
			$min = min($temp, $min);
		}
	}
	$sum -= $min / 2;

	printf("%.1f", $sum);
	print("\n");
	for ($i = 0; $i < $inp_K; $i++) {
		$count = count($KART[$i]);
		print($count);
		print(" ");
		$cou = 0;
		$c = 0;
		foreach ($KART[$i] as $as_i) {
			if ($i !== $inp_K - 1) {
				print($as_i);
				$cou++;
				if ($cou != $count) {
					print(" ");
				} else {
					print("\n");
				}
			} else {
				print($as_i);
				$c++;
				if ($c != $count) {
					print(" ");
				}
			}
		}
	}
	$Scanner->close();
}

ob_end_clean();
solve();

//error_reporting(0);
//$Scanner = new Scanner("php://stdin");
class Scanner{
	private $Stream;
	private $Scanners = array();
	private $Id = 0;

	public function __construct($opend){
		if((!is_file($opend) && !is_link($opend)) && $opend !== "php://stdin"){
  			print("file or link or ''php://stdin' err");
  			exit;
		}

		$this->Stream = fopen($opend, 'r');
		$contents = stream_get_contents($this->Stream);

		//err $c_row = array("\n", "\r", "\r\n");
		$c_row = array("\r\n", "\r", "\n");
		$contents = str_replace($c_row, " ", $contents);
		$this->Scanners = explode(" ", $contents);
	}

	function Scan(){
		$x = $this->Id;
		$sc = $this->Scanners[$x];
		$this->Id = ++$x;
		return $sc;
	}

	function close(){
		fclose($this->Stream);
	}
}

/*
====begin=====

//input    $inp_ or upper
//block    $temp_
//two block$ttemp_
//as 	   $as_
//instance $(Upper)
//ref      $ref
//class menba $^Upper

====end=======

===== class begin =====

//error_reporting(0);
//$Scanner = new Scanner("php://stdin");
//ref "#109_div2_B_1230942 laurenceHR"
class LineScanner{
	private $Stream;
	private $Scanners = array();
	private $LineIds_Of_ScanIds= array();
	private $LinesScanners = array();
	private $LastScanIds_Of_LineIds = array();
	private $Scan_number = 0;
	private $Scanline_number = 0;

	public function __construct($opend){
		if((!is_file($opend) && !is_link($opend)) && $opend !== "php://stdin"){
  			print("file or link err");
  			exit;
		}

		$this->Stream = fopen($opend, 'r');
		$contents = stream_get_contents($this->Stream);

		$temp_lines = explode("\n", $contents);
		$temp_linescanners = array();
		$temp_x = 0;
		$temp_y = 0;
		//--attention for initting of array--(these is not needed but for easily reading)//
		$ttemp_scanners = array();
		//$del = Array("\n","\r","\n\r");
		foreach ($temp_lines as $as_line) {
			if (strlen($as_line) === 0) {
				print("input err");
			}

			//$as_line = str_replace($del,'',$as_line);
			$temp_linescanners[] = $as_line;
			$ttemp_line_scanners = explode(" ", $as_line);
			//$ttemp_scanners = array();
			foreach ($ttemp_line_scanners as $as_sc) {
				$ttemp_scanners[] = $as_sc;
				$this->LineIds_Of_ScanIds[$temp_x] = $temp_y;
				$temp_x++;
			}
			$this->LastScanIds_Of_LineIds[$temp_y] = $temp_x - 1;
			$temp_y++;
		}
		$this->Scanners = $ttemp_scanners;
		$this->LinesScanners = $temp_linescanners;
	}

	function Scan(){
		$x = $this->Scan_number;
		$y = $this->Scanline_number;
		if ($this->LineIds_Of_ScanIds[$x] === false || $this->LastScanIds_Of_LineIds[$y] === false) {
			print("scan err");
		}

		$sc = $this->Scanners[$x];
		//--attention for ++$x//
		//$this->Scan_number = $x++;
		$this->Scan_number = ++$x;
		$this->Scanline_number = $this->LineIds_Of_ScanIds[$x];
		return $sc;
	}

	function LineScan(){
		$x = $this->Scan_number;
		$y = $this->Scanline_number;
		if ($this->LineIds_Of_ScanIds[$x] === false || $this->LastScanIds_Of_LineIds[$y] === false) {
			print("linescan err");
		}

		$lsc = $this->LinesScanners[$y];
		$this->Scan_number = $this->LastScanIds_Of_LineIds[$y] + 1;
		$this->Scanline_number = $y + 1;
		return $lsc;
	}

	function close(){
		fclose($this->Stream);
	}
}

class Token{
	private $token;
	private $tok;

	public function __construct($str_line, $tok) {
		$this->tok = $tok;
		$this->token = strtok($str_line, $this->tok);
	}

	public function nextToken() {
		$thisToken = $this->token;
		$this->token = strtok($this->tok);
		return $thisToken;
	}

	public function nextFloat() {
		return (float)$this->nextToken();
	}

  	public function nextInt() {
		return (int)$this->nextToken();
	}

	public function nextIntArray() {
		$temp_arr = array();
		$flag = -1;
		while ($flag !== 1) {
			$thisToken = $this->nextToken();
			if ($thisToken !== false) {
				$temp_arr[] = $thisToken;
			} else {
				$flag = 1;
			}
		}
		return $temp_arr;
	}

	public function nnextIntArray($num) {
		$temp_arr = array();
		for ($i = 0; $i < $num; $i++) {
			$temp_arr[] = (int)$this->token;
		}
		return $temp_arr;
	}
}
===== class end ======

=== function begin ===

function get_line() {
        $stdin = fopen("php://stdin", "r");
        $line = rtrim($stdin, "\n");
        fclose($stdin);
        return $line;
}

function num_printf($i){
	if (is_float($i)) {
		printf("%.0f", $i);
	}
	if (is_int($i)) {
		printf("%d", $i);
	}
}

function array_printf(array $array) {
		$message = "";
		foreach ($array as $value) {
			$message .= "$value" . " ";
		}
		$message = rtrim($message);
		printf('%s', $message);
}

== function end ======
*/

?>

<?php
error_reporting(0);

function solve(){
	$Scanner = new Scanner("php://stdin");
	//$Scanner = new Scanner("input.txt");

	$inp_N = (int)$Scanner->Scan();
	$inp_K = (int)$Scanner->Scan();

	for ($i = 0; $i < $inp_N; $i++) {
		 $PRICE = $Scanner->Scan();
		 $TYPE = (int)$Scanner->Scan();
		 if ($TYPE === 1) $STOOLS[$i + 1] = $PRICE;
		 else if ($TYPE === 2) $PENCILS[$i + 1] = $PRICE;
	}

	//if (!asort($STOOLS)) print("err");
	//In case $STOOLS is null, this is printed;

	asort($STOOLS);
	$min = 0;
	$sum = 0;
	$num = 0;
	$diff = count($STOOLS) - $inp_K;
	if ($diff >= 0) {
		foreach ($STOOLS as $STOOLS_key => $STOOLS_val) {
			if ($num <= $diff) {
				if ($num === 0) $min = $STOOLS_val / 2;
				$sum += $STOOLS_val;
				$KART[0][] = $STOOLS_key;
			} else {
				$sum += $STOOLS_val / 2;
				$KART[$num - $diff][] = $STOOLS_key;
			}
			$num++;
		}

		$PEN_FLAG = 0;
		foreach ($PENCILS as $PENCILS_key => $PENCILS_val) {
			if ($PEN_FLAG === 0) {
				//$min = min($min, $PENCILS_val / 2) + ;
				if ($min > $PENCILS_val / 2) $min = $PENCILS_val / 2 + 2 * $min;
				elseif ($min <= $PENCILS_val / 2) $min = $PENCILS_val + $min;
				$PEN_FLAG = 1;
			}
			$sum += $PENCILS_val;
			$KART[0][] = $PENCILS_key;
		}
		$sum = $sum + $min;
	} elseif($diff < 0)	{
		foreach ($STOOLS as $STOOLS_key => $STOOLS_val) {
			$sum += $STOOLS_val / 2;
			$KART[$num][] = $STOOLS_key;
			$num++;
		}

		foreach ($PENCILS as $PENCILS_key => $PENCILS_val) {
			if ($diff !== 0) {
				$sum += $PENCILS_val;
				$KART[$num][] = $PENCILS_key;
				$diff++;
				$num++;
			} else {
				$sum += $PENCILS_val;
				$KART[$inp_K - 1][] = $PENCILS_key;
			}
		}
	}
	printf("%.1f", $sum);
	print("\n");
	for ($i = 0; $i < $inp_K; $i++) {
		$count = count($KART[$i]);
		//print($sum);
		print($count);
		print(" ");
		$cou = 0;
		$c = 0;
		foreach ($KART[$i] as $as_i) {
			if ($i !== $inp_K - 1) {
				print($as_i);
				$cou++;
				//if ($cou != $count - 1) {
				if ($cou != $count) {
					print(" ");
				} else {
					print("\n");
				}
			} else {
				print($as_i);
				$c++;
				//if ($c != $count - 1) {
				if ($c != $count) {
					print(" ");
				}
			}
		}
	}
	$Scanner->close();
}

ob_end_clean();
solve();

//error_reporting(0);
//$Scanner = new Scanner("php://stdin");
class Scanner{
	private $Stream;
	private $Scanners = array();
	private $Id = 0;

	public function __construct($opend){
		if((!is_file($opend) && !is_link($opend)) && $opend !== "php://stdin"){
  			print("file or link or ''php://stdin' err");
  			exit;
		}

		$this->Stream = fopen($opend, 'r');
		$contents = stream_get_contents($this->Stream);

		//err $c_row = array("\n", "\r", "\r\n");
		$c_row = array("\r\n", "\r", "\n");
		$contents = str_replace($c_row, " ", $contents);
		$this->Scanners = explode(" ", $contents);
	}

	function Scan(){
		$x = $this->Id;
		$sc = $this->Scanners[$x];
		$this->Id = ++$x;
		return $sc;
	}

	function close(){
		fclose($this->Stream);
	}
}

/*
====begin=====

//input    $inp_ or upper
//block    $temp_
//two block$ttemp_
//as 	   $as_
//instance $(Upper)
//ref      $ref
//class menba $^Upper

====end=======

===== class begin =====

//error_reporting(0);
//$Scanner = new Scanner("php://stdin");
//ref "#109_div2_B_1230942 laurenceHR"
class LineScanner{
	private $Stream;
	private $Scanners = array();
	private $LineIds_Of_ScanIds= array();
	private $LinesScanners = array();
	private $LastScanIds_Of_LineIds = array();
	private $Scan_number = 0;
	private $Scanline_number = 0;

	public function __construct($opend){
		if((!is_file($opend) && !is_link($opend)) && $opend !== "php://stdin"){
  			print("file or link err");
  			exit;
		}

		$this->Stream = fopen($opend, 'r');
		$contents = stream_get_contents($this->Stream);

		$temp_lines = explode("\n", $contents);
		$temp_linescanners = array();
		$temp_x = 0;
		$temp_y = 0;
		//--attention for initting of array--(these is not needed but for easily reading)//
		$ttemp_scanners = array();
		//$del = Array("\n","\r","\n\r");
		foreach ($temp_lines as $as_line) {
			if (strlen($as_line) === 0) {
				print("input err");
			}

			//$as_line = str_replace($del,'',$as_line);
			$temp_linescanners[] = $as_line;
			$ttemp_line_scanners = explode(" ", $as_line);
			//$ttemp_scanners = array();
			foreach ($ttemp_line_scanners as $as_sc) {
				$ttemp_scanners[] = $as_sc;
				$this->LineIds_Of_ScanIds[$temp_x] = $temp_y;
				$temp_x++;
			}
			$this->LastScanIds_Of_LineIds[$temp_y] = $temp_x - 1;
			$temp_y++;
		}
		$this->Scanners = $ttemp_scanners;
		$this->LinesScanners = $temp_linescanners;
	}

	function Scan(){
		$x = $this->Scan_number;
		$y = $this->Scanline_number;
		if ($this->LineIds_Of_ScanIds[$x] === false || $this->LastScanIds_Of_LineIds[$y] === false) {
			print("scan err");
		}

		$sc = $this->Scanners[$x];
		//--attention for ++$x//
		//$this->Scan_number = $x++;
		$this->Scan_number = ++$x;
		$this->Scanline_number = $this->LineIds_Of_ScanIds[$x];
		return $sc;
	}

	function LineScan(){
		$x = $this->Scan_number;
		$y = $this->Scanline_number;
		if ($this->LineIds_Of_ScanIds[$x] === false || $this->LastScanIds_Of_LineIds[$y] === false) {
			print("linescan err");
		}

		$lsc = $this->LinesScanners[$y];
		$this->Scan_number = $this->LastScanIds_Of_LineIds[$y] + 1;
		$this->Scanline_number = $y + 1;
		return $lsc;
	}

	function close(){
		fclose($this->Stream);
	}
}

class Token{
	private $token;
	private $tok;

	public function __construct($str_line, $tok) {
		$this->tok = $tok;
		$this->token = strtok($str_line, $this->tok);
	}

	public function nextToken() {
		$thisToken = $this->token;
		$this->token = strtok($this->tok);
		return $thisToken;
	}

	public function nextFloat() {
		return (float)$this->nextToken();
	}

  	public function nextInt() {
		return (int)$this->nextToken();
	}

	public function nextIntArray() {
		$temp_arr = array();
		$flag = -1;
		while ($flag !== 1) {
			$thisToken = $this->nextToken();
			if ($thisToken !== false) {
				$temp_arr[] = $thisToken;
			} else {
				$flag = 1;
			}
		}
		return $temp_arr;
	}

	public function nnextIntArray($num) {
		$temp_arr = array();
		for ($i = 0; $i < $num; $i++) {
			$temp_arr[] = (int)$this->token;
		}
		return $temp_arr;
	}
}
===== class end ======

=== function begin ===

function get_line() {
        $stdin = fopen("php://stdin", "r");
        $line = rtrim($stdin, "\n");
        fclose($stdin);
        return $line;
}

function num_printf($i){
	if (is_float($i)) {
		printf("%.0f", $i);
	}
	if (is_int($i)) {
		printf("%d", $i);
	}
}

function array_printf(array $array) {
		$message = "";
		foreach ($array as $value) {
			$message .= "$value" . " ";
		}
		$message = rtrim($message);
		printf('%s', $message);
}

== function end ======
*/

?>

<?php
error_reporting(0);

function solve(){
	$Scanner = new Scanner("php://stdin");
	//$Scanner = new Scanner("input.txt");

	$inp_N = (int)$Scanner->Scan();
	$inp_K = (int)$Scanner->Scan();

	for ($i = 0; $i < $inp_N; $i++) {
		 $PRICE = $Scanner->Scan();
		 $TYPE = (int)$Scanner->Scan();
		 if ($TYPE === 1) $STOOLS[$i + 1] = $PRICE;
		 else if ($TYPE === 2) $PENCILS[$i + 1] = $PRICE;
	}

	//if (!asort($STOOLS)) print("err");
	//In case $STOOLS is null, this is printed;

	asort($STOOLS);
	$min = 0;
	$sum = 0;
	$num = 0;
	$diff = count($STOOLS) - $inp_K;
	if ($diff >= 0) {
		foreach ($STOOLS as $STOOLS_key => $STOOLS_val) {
			if ($num <= $diff) {
				if ($num === 0) $min = $STOOLS_val / 2;
				else $sum += $STOOLS_val;
				$KART[0][] = $STOOLS_key;
			} else {
				$sum += $STOOLS_val / 2;
				$KART[$num - $diff][] = $STOOLS_key;
			}
			$num++;
		}

		$PEN_FLAG = 0;
		foreach ($PENCILS as $PENCILS_key => $PENCILS_val) {
			if ($PEN_FLAG === 0) {
				//$min = min($min, $PENCILS_val / 2) + ;
				if ($min > $PENCILS_val / 2) $min = $PENCILS_val / 2 + 2 * $min;
				elseif ($min <= $PENCILS_val / 2) $min = $PENCILS_val + $min;
				$PEN_FLAG = 1;
			}
			$sum += $PENCILS_val;
			$KART[0][] = $PENCILS_key;
		}
		$sum = $sum + $min;
	} elseif($diff < 0)	{
		foreach ($STOOLS as $STOOLS_key => $STOOLS_val) {
			$sum += $STOOLS_val / 2;
			$KART[$num][] = $STOOLS_key;
			$num++;
		}

		foreach ($PENCILS as $PENCILS_key => $PENCILS_val) {
			if ($diff !== 0) {
				$sum += $PENCILS_val;
				$KART[$num][] = $PENCILS_key;
				$diff++;
				$num++;
			} else {
				$sum += $PENCILS_val;
				$KART[$inp_K - 1][] = $PENCILS_key;
			}
		}
	}
	printf("%.1f", $sum);
	print("\n");
	for ($i = 0; $i < $inp_K; $i++) {
		$count = count($KART[$i]);
		//print($sum);
		print($count);
		print(" ");
		$cou = 0;
		$c = 0;
		foreach ($KART[$i] as $as_i) {
			if ($i !== $inp_K - 1) {
				print($as_i);
				$cou++;
				//if ($cou != $count - 1) {
				if ($cou != $count) {
					print(" ");
				} else {
					print("\n");
				}
			} else {
				print($as_i);
				$c++;
				//if ($c != $count - 1) {
				if ($c != $count) {
					print(" ");
				}
			}
		}
	}
	$Scanner->close();
}

ob_end_clean();
solve();

//error_reporting(0);
//$Scanner = new Scanner("php://stdin");
class Scanner{
	private $Stream;
	private $Scanners = array();
	private $Id = 0;

	public function __construct($opend){
		if((!is_file($opend) && !is_link($opend)) && $opend !== "php://stdin"){
  			print("file or link or ''php://stdin' err");
  			exit;
		}

		$this->Stream = fopen($opend, 'r');
		$contents = stream_get_contents($this->Stream);

		//err $c_row = array("\n", "\r", "\r\n");
		$c_row = array("\r\n", "\r", "\n");
		$contents = str_replace($c_row, " ", $contents);
		$this->Scanners = explode(" ", $contents);
	}

	function Scan(){
		$x = $this->Id;
		$sc = $this->Scanners[$x];
		$this->Id = ++$x;
		return $sc;
	}

	function close(){
		fclose($this->Stream);
	}
}

/*
====begin=====

//input    $inp_ or upper
//block    $temp_
//two block$ttemp_
//as 	   $as_
//instance $(Upper)
//ref      $ref
//class menba $^Upper

====end=======

===== class begin =====

//error_reporting(0);
//$Scanner = new Scanner("php://stdin");
//ref "#109_div2_B_1230942 laurenceHR"
class LineScanner{
	private $Stream;
	private $Scanners = array();
	private $LineIds_Of_ScanIds= array();
	private $LinesScanners = array();
	private $LastScanIds_Of_LineIds = array();
	private $Scan_number = 0;
	private $Scanline_number = 0;

	public function __construct($opend){
		if((!is_file($opend) && !is_link($opend)) && $opend !== "php://stdin"){
  			print("file or link err");
  			exit;
		}

		$this->Stream = fopen($opend, 'r');
		$contents = stream_get_contents($this->Stream);

		$temp_lines = explode("\n", $contents);
		$temp_linescanners = array();
		$temp_x = 0;
		$temp_y = 0;
		//--attention for initting of array--(these is not needed but for easily reading)//
		$ttemp_scanners = array();
		//$del = Array("\n","\r","\n\r");
		foreach ($temp_lines as $as_line) {
			if (strlen($as_line) === 0) {
				print("input err");
			}

			//$as_line = str_replace($del,'',$as_line);
			$temp_linescanners[] = $as_line;
			$ttemp_line_scanners = explode(" ", $as_line);
			//$ttemp_scanners = array();
			foreach ($ttemp_line_scanners as $as_sc) {
				$ttemp_scanners[] = $as_sc;
				$this->LineIds_Of_ScanIds[$temp_x] = $temp_y;
				$temp_x++;
			}
			$this->LastScanIds_Of_LineIds[$temp_y] = $temp_x - 1;
			$temp_y++;
		}
		$this->Scanners = $ttemp_scanners;
		$this->LinesScanners = $temp_linescanners;
	}

	function Scan(){
		$x = $this->Scan_number;
		$y = $this->Scanline_number;
		if ($this->LineIds_Of_ScanIds[$x] === false || $this->LastScanIds_Of_LineIds[$y] === false) {
			print("scan err");
		}

		$sc = $this->Scanners[$x];
		//--attention for ++$x//
		//$this->Scan_number = $x++;
		$this->Scan_number = ++$x;
		$this->Scanline_number = $this->LineIds_Of_ScanIds[$x];
		return $sc;
	}

	function LineScan(){
		$x = $this->Scan_number;
		$y = $this->Scanline_number;
		if ($this->LineIds_Of_ScanIds[$x] === false || $this->LastScanIds_Of_LineIds[$y] === false) {
			print("linescan err");
		}

		$lsc = $this->LinesScanners[$y];
		$this->Scan_number = $this->LastScanIds_Of_LineIds[$y] + 1;
		$this->Scanline_number = $y + 1;
		return $lsc;
	}

	function close(){
		fclose($this->Stream);
	}
}

class Token{
	private $token;
	private $tok;

	public function __construct($str_line, $tok) {
		$this->tok = $tok;
		$this->token = strtok($str_line, $this->tok);
	}

	public function nextToken() {
		$thisToken = $this->token;
		$this->token = strtok($this->tok);
		return $thisToken;
	}

	public function nextFloat() {
		return (float)$this->nextToken();
	}

  	public function nextInt() {
		return (int)$this->nextToken();
	}

	public function nextIntArray() {
		$temp_arr = array();
		$flag = -1;
		while ($flag !== 1) {
			$thisToken = $this->nextToken();
			if ($thisToken !== false) {
				$temp_arr[] = $thisToken;
			} else {
				$flag = 1;
			}
		}
		return $temp_arr;
	}

	public function nnextIntArray($num) {
		$temp_arr = array();
		for ($i = 0; $i < $num; $i++) {
			$temp_arr[] = (int)$this->token;
		}
		return $temp_arr;
	}
}
===== class end ======

=== function begin ===

function get_line() {
        $stdin = fopen("php://stdin", "r");
        $line = rtrim($stdin, "\n");
        fclose($stdin);
        return $line;
}

function num_printf($i){
	if (is_float($i)) {
		printf("%.0f", $i);
	}
	if (is_int($i)) {
		printf("%d", $i);
	}
}

function array_printf(array $array) {
		$message = "";
		foreach ($array as $value) {
			$message .= "$value" . " ";
		}
		$message = rtrim($message);
		printf('%s', $message);
}

== function end ======
*/

?>

<?php
//error_reporting(0);

class Item{
	private $index;
	private $type;
	private $price;

	public function __construct($index, $type, $price) {
		$this->index = $index;
		$this->type = $type;
		$this->price = $price;
	}

	public function getIndex() {
		return $this->index;
	}

	public function getPrice() {
		return $this->price;
	}

	public function getType() {
		return $this->type;
	}

    static function compareItem($a_item, $b_item) {
		$a_t = $a_item->getType();
		$b_t = $b_item->getType();
		$a_p = $a_item->getPrice();
		$b_p = $b_item->getPrice();

		if ($a_t < $b_t) return -1;
		elseif ($a_t > $b_t) return 1;
		elseif ($a_t === $b_t) {
			if ($a_p > $b_p) return -1;
			elseif ($a_p === $b_p) return 0;
			elseif ($a_p < $b_p) return 1;
		}
	}
}
/*
function compare(Item $a_item , Item $b_item){
	//$a_t = $a->getType();
	//$b_t = $b->getType();
	//$a_p = $a->getPrice();
	//$b_p = $b->getPrice();
	$a_t = $a_item->getType();
	$b_t = $b_item->getType();
	$a_p = $a_item->getPrice();
	$b_p = $b_item->getPrice();

	if ($a_t < $b_t) {
		return -1;
	} elseif ($a_t > $b_t) {
		return 1;
	//} elseif ($a_t = $b_t) {
	} elseif ($a_t === $b_t) {
		if ($a_p > $b_p) {
			//return 1;
			return -1;
		//} elseif ($a_p = $b_p) {
		} elseif ($a_p === $b_p) {
			return 0;
		} elseif ($a_p < $b_p) {
			//return -1;
			return 1;
		}
	}
}
*/
function solve(){
	$Scanner = new Scanner("php://stdin");
	//$Scanner = new Scanner("input.txt");

	$inp_N = (int)$Scanner->Scan();
	$inp_K = (int)$Scanner->Scan();

	for ($i = 0; $i < $inp_N; $i++) {
		$PRICE = $Scanner->Scan();
		$TYPE = (int)$Scanner->Scan();
		$ITEMS[] = new Item($i + 1, $TYPE, $PRICE);
	}

	usort($ITEMS, array("ITEM", "compare"));
	//usort($ITEMS, "compare");
	for ($i = 0; $i < $inp_N; $i++) {
		if ($i < $inp_K - 1) {
			//$KART[$i] = $ITEMS[$i]->getIndex();
			$KART[$i][] = $ITEMS[$i]->getIndex();
		} elseif ($i >= $inp_K - 1) {
			$KART[$inp_K - 1][] = $ITEMS[$i]->getIndex();
		}
	}

	for ($i = 0; $i < $inp_N; $i++) {
		$type = $ITEMS[$i]->getType();
		if ($i < $inp_K - 1 && $type === 1) {
			$sum += $ITEMS[$i]->getPrice() / 2;
		} elseif ($i >= $inp_K - 1 || $type !== 1) {
			$sum += $ITEMS[$i]->getPrice();
		}
	}

	//$min = 1E9 + 1;
	if ($ITEMS[$inp_K - 1]->getType() === 1) {
		$min = 1E9 + 1;
		for ($i = $inp_K - 1; $i < $inp_N; $i++) {
			$temp = $ITEMS[$i]->getPrice();
			$min = min($temp, $min);
		}
	}
	$sum -= $min / 2;

	printf("%.1f", $sum);
	print("\n");
	for ($i = 0; $i < $inp_K; $i++) {
		$count = count($KART[$i]);
		//print($sum);
		print($count);
		print(" ");
		$cou = 0;
		$c = 0;
		foreach ($KART[$i] as $as_i) {
			if ($i !== $inp_K - 1) {
				print($as_i);
				$cou++;
				//if ($cou != $count - 1) {
				if ($cou != $count) {
					print(" ");
				} else {
					print("\n");
				}
			} else {
				print($as_i);
				$c++;
				//if ($c != $count - 1) {
				if ($c != $count) {
					print(" ");
				}
			}
		}
	}
	$Scanner->close();
}

ob_end_clean();
solve();

//error_reporting(0);
//$Scanner = new Scanner("php://stdin");
class Scanner{
	private $Stream;
	private $Scanners = array();
	private $Id = 0;

	public function __construct($opend){
		if((!is_file($opend) && !is_link($opend)) && $opend !== "php://stdin"){
  			print("file or link or ''php://stdin' err");
  			exit;
		}

		$this->Stream = fopen($opend, 'r');
		$contents = stream_get_contents($this->Stream);

		//err $c_row = array("\n", "\r", "\r\n");
		$c_row = array("\r\n", "\r", "\n");
		$contents = str_replace($c_row, " ", $contents);
		$this->Scanners = explode(" ", $contents);
	}

	function Scan(){
		$x = $this->Id;
		$sc = $this->Scanners[$x];
		$this->Id = ++$x;
		return $sc;
	}

	function close(){
		fclose($this->Stream);
	}
}

/*
====begin=====

//input    $inp_ or upper
//block    $temp_
//two block$ttemp_
//as 	   $as_
//instance $(Upper)
//ref      $ref
//class menba $^Upper

====end=======

===== class begin =====

//error_reporting(0);
//$Scanner = new Scanner("php://stdin");
//ref "#109_div2_B_1230942 laurenceHR"
class LineScanner{
	private $Stream;
	private $Scanners = array();
	private $LineIds_Of_ScanIds= array();
	private $LinesScanners = array();
	private $LastScanIds_Of_LineIds = array();
	private $Scan_number = 0;
	private $Scanline_number = 0;

	public function __construct($opend){
		if((!is_file($opend) && !is_link($opend)) && $opend !== "php://stdin"){
  			print("file or link err");
  			exit;
		}

		$this->Stream = fopen($opend, 'r');
		$contents = stream_get_contents($this->Stream);

		$temp_lines = explode("\n", $contents);
		$temp_linescanners = array();
		$temp_x = 0;
		$temp_y = 0;
		//--attention for initting of array--(these is not needed but for easily reading)//
		$ttemp_scanners = array();
		//$del = Array("\n","\r","\n\r");
		foreach ($temp_lines as $as_line) {
			if (strlen($as_line) === 0) {
				print("input err");
			}

			//$as_line = str_replace($del,'',$as_line);
			$temp_linescanners[] = $as_line;
			$ttemp_line_scanners = explode(" ", $as_line);
			//$ttemp_scanners = array();
			foreach ($ttemp_line_scanners as $as_sc) {
				$ttemp_scanners[] = $as_sc;
				$this->LineIds_Of_ScanIds[$temp_x] = $temp_y;
				$temp_x++;
			}
			$this->LastScanIds_Of_LineIds[$temp_y] = $temp_x - 1;
			$temp_y++;
		}
		$this->Scanners = $ttemp_scanners;
		$this->LinesScanners = $temp_linescanners;
	}

	function Scan(){
		$x = $this->Scan_number;
		$y = $this->Scanline_number;
		if ($this->LineIds_Of_ScanIds[$x] === false || $this->LastScanIds_Of_LineIds[$y] === false) {
			print("scan err");
		}

		$sc = $this->Scanners[$x];
		//--attention for ++$x//
		//$this->Scan_number = $x++;
		$this->Scan_number = ++$x;
		$this->Scanline_number = $this->LineIds_Of_ScanIds[$x];
		return $sc;
	}

	function LineScan(){
		$x = $this->Scan_number;
		$y = $this->Scanline_number;
		if ($this->LineIds_Of_ScanIds[$x] === false || $this->LastScanIds_Of_LineIds[$y] === false) {
			print("linescan err");
		}

		$lsc = $this->LinesScanners[$y];
		$this->Scan_number = $this->LastScanIds_Of_LineIds[$y] + 1;
		$this->Scanline_number = $y + 1;
		return $lsc;
	}

	function close(){
		fclose($this->Stream);
	}
}

class Token{
	private $token;
	private $tok;

	public function __construct($str_line, $tok) {
		$this->tok = $tok;
		$this->token = strtok($str_line, $this->tok);
	}

	public function nextToken() {
		$thisToken = $this->token;
		$this->token = strtok($this->tok);
		return $thisToken;
	}

	public function nextFloat() {
		return (float)$this->nextToken();
	}

  	public function nextInt() {
		return (int)$this->nextToken();
	}

	public function nextIntArray() {
		$temp_arr = array();
		$flag = -1;
		while ($flag !== 1) {
			$thisToken = $this->nextToken();
			if ($thisToken !== false) {
				$temp_arr[] = $thisToken;
			} else {
				$flag = 1;
			}
		}
		return $temp_arr;
	}

	public function nnextIntArray($num) {
		$temp_arr = array();
		for ($i = 0; $i < $num; $i++) {
			$temp_arr[] = (int)$this->token;
		}
		return $temp_arr;
	}
}
===== class end ======

=== function begin ===

function get_line() {
        $stdin = fopen("php://stdin", "r");
        $line = rtrim($stdin, "\n");
        fclose($stdin);
        return $line;
}

function num_printf($i){
	if (is_float($i)) {
		printf("%.0f", $i);
	}
	if (is_int($i)) {
		printf("%d", $i);
	}
}

function array_printf(array $array) {
		$message = "";
		foreach ($array as $value) {
			$message .= "$value" . " ";
		}
		$message = rtrim($message);
		printf('%s', $message);
}

== function end ======
*/

?>