Ethflow Round 1 (Codeforces Round 1001, Div. 1 + Div. 2)
F
Traveling Salescat
Codeforces
2900
原题
← E2G →
翻译中…

You are a cat selling fun algorithm problems. Today, you want to recommend your fun algorithm problems to $k$ cities.

翻译中…

There are a total of $n$ cities, each with two parameters $a_i$ and $b_i$. Between any two cities $i,j$ ($i\ne j$), there is a bidirectional road with a length of $\max(a_i + b_j , b_i + a_j)$. The cost of a path is defined as the total length of roads between every two adjacent cities along the path.

翻译中…

For $k=2,3,\ldots,n$, find the minimum cost among all simple paths containing exactly $k$ distinct cities.

翻译中…

Input

翻译中…

The first line of input contains a single integer $t$ ($1 \leq t \leq 1500$) — the number of test cases.

翻译中…

For each test case, the first line contains a single integer $n$ ($2 \leq n \leq 3\cdot 10^3$) — the number of cities.

翻译中…

Then $n$ lines follow, the $i$-th line contains two integers $a_i,b_i$ ($0 \leq a_i,b_i \leq 10^9$) — the parameters of city $i$.

翻译中…

It is guaranteed that the sum of $n^2$ over all test cases does not exceed $9\cdot 10^6$.

翻译中…

Output

翻译中…

For each test case, print $n-1$ integers in one line. The $i$-th integer represents the minimum cost when $k=i+1$.

翻译中…

Note

翻译中…

In the first test case:

翻译中…
  • For $k=2$, the optimal path is $1\to 2$ with a cost of $\max(0+1,2+2)=4$.
  • For $k=3$, the optimal path is $2\to 1\to 3$ with a cost of $\max(0+1,2+2)+\max(0+3,3+2)=4+5=9$.
翻译中…

In the second test case:

翻译中…
  • For $k=2$, the optimal path is $1\to 4$.
  • For $k=3$, the optimal path is $2\to 3\to 5$.
  • For $k=4$, the optimal path is $4\to 1\to 3\to 5$.
  • For $k=5$, the optimal path is $5\to 2\to 3\to 1\to 4$.
翻译中…

样例

Input #1
3
3
0 2
2 1
3 3
5
2 7
7 5
6 3
1 8
7 5
8
899167687 609615846
851467150 45726720
931502759 23784096
918190644 196992738
142090421 475722765
409556751 726971942
513558832 998277529
294328304 434714258
Output #1
4 9
10 22 34 46
770051069 1655330585 2931719265 3918741472 5033924854 6425541981 7934325514
InputCopy OutputCopy
题目信息
题号
2062F
时间限制
2 s
内存限制
512 MB
标签
构造
动态规划
计算几何
图论
贪心
数学
排序

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。