<?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);

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

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 ======
*/

?>