#P17425. [ICPC 2018 Xuzhou R] Rikka with A Long Colour Palette

    ID: 19927 远端评测题 6000ms 512MiB 尝试: 0 已通过: 0 显示难度普及+/提高− 上传者: 标签>贪心2018Special JudgeICPC

[ICPC 2018 Xuzhou R] Rikka with A Long Colour Palette

Problem Description

$\textit{Blue, the colour of the sky, the sea and your eyes.}$

$\textit{Green, the colour of nature, fertility and life.}$

$\textit{Purple, the colour of good judgment, and of people seeking spiritual fulfilment.}$

$\textit{Orange, the only colour that is also a fruit.}$

Yellow, the colour in smiley faces.\textit{Yellow, the colour in smiley faces.}

Red, the warmest of all.\textit{Red, the warmest of all.}

Rikka loves them all, but what is her favourite colour? She has found kk different colours, numbered from 11 to kk, and she knows that the best colour should be the one after mixing them all together. The best colour is called the DREAM.

Rikka has also prepared a long and narrow colour palette of length 10910^9. She designates nn segments in the palette. A segment described by two integers ll and rr (0≤l<r≤1090 \le l < r \le 10^9) represents an area of the palette where the distance between the leftmost end of the palette and the left endpoint (resp. the right endpoint) of the area is ll (resp. rr).

She will for each segment designated smear the pigment of any of these colours (from 11 to kk) which she has found evenly on it. Some areas may contain pigments of several different colours, since these segments may intersect. If some areas contain all these kk different colours which she has found, it would blend into the DREAM.

Now, Rikka wants you to maximize the total length of all areas in the palette such that each part of them can blend into the DREAM. You also need to provide a feasible plan.

Input Format

The input contains several test cases, and the first line contains a single integer TT (1≤T≤10001 \le T \le 1000), the number of test cases.

For each test case, the first line contains two integers nn (1≤n≤2×1051 \le n \le 2 \times 10^5), the number of segments designated by Rikka, and kk (1≤k≤2×1051 \le k \le 2 \times 10^5), the number of colours which Rikka has found.

Each of the following nn lines contains two integers ll and rr (0≤l<r≤1090 \le l < r \le 10^9), representing the ii-th segment in the palette.

The input guarantees that the sum of nn in all test cases is at most 2×1062 \times 10^6.

Output Format

For each test case, output two lines. Firstly, output a line with a single integer, the largest total length of areas required. Then, output a line with nn space-separated integers describing a feasible plan, where the ii-th number is the colour for the ii-th segment.

All feasible plans are allowed, so you can output any of them.

1
3 2
1 5
2 4
3 6
3
1 2 2