PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#GD0000139. Phân giỏ hàng để được giảm giá (Discounts)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Phân giỏ hàng để được giảm giá (Discounts)

Discounts

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

A store sells nn items, item ii priced cic_i and having type tit_i: type 11 is a stool, type 22 is a pencil. Buy every item using exactly kk nonempty shopping carts, placing each item in exactly one cart. A cart containing at least one stool gets 50% off exactly one cheapest item in that cart; carts with no stool receive no discount. Print the minimum total cost and any optimal partition.

Input

The first line contains n,kn,k. Each of the next nn lines contains ci,tic_i,t_i. Items are indexed 11 through nn in input order.

Output

Print the minimum price with exactly one digit after the decimal point. Then print exactly kk lines: qjq_j followed by the qjq_j item indices in cart jj. Every cart is nonempty and each item appears once.

Subtasks

  • Subtask 1 (20 points): 1≤k≤n≤121\le k\le n\le 12; 1≤ci≤1091\le c_i\le10^9; ti∈{1,2}t_i\in\{1,2\}.
  • Subtask 2 (30 points): 1≤k≤n≤1001\le k\le n\le 100; 1≤ci≤1091\le c_i\le10^9; ti∈{1,2}t_i\in\{1,2\}.
  • Subtask 3 (50 points): 1≤k≤n≤10001\le k\le n\le 1000; 1≤ci≤1091\le c_i\le10^9; ti∈{1,2}t_i\in\{1,2\}.

Examples

Input

3 2
2 1
3 2
3 1

Output

5.5
1 3
2 1 2

Explanation

Put item 33 (a stool priced 33) alone in the first cart, paying 1.51.5. Put items 11 (a 22 stool) and 22 (a 33 pencil) in the second cart: the cheapest item is reduced to 11, so this cart costs 44. Total payment is 5.55.5.