欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1614B.Divan and a New Project
Divan and a New Project
The company "Divan's Sofas" is planning to build different buildings on a coordinate line so that:
- the coordinate of each building is an integer number;
- no two buildings stand at the same point.
Let be the coordinate of the -th building. To get from the building to the building , Divan spends minutes, where is the absolute value of .
All buildings that Divan is going to build can be numbered from to . The businessman will live in the building , the new headquarters of "Divan's Sofas". In the first ten years after construction Divan will visit the -th building times, each time spending minutes for walking.
Divan asks you to choose the coordinates for all buildings so that over the next ten years the businessman will spend as little time for walking as possible.
Input
Each test contains several test cases. The first line contains one integer number () — the number of test cases.
The first line of each case contains an integer () — the number of buildings that "Divan's Sofas" is going to build, apart from the headquarters.
The second line contains the sequence (), where is the number of visits to the -th building.
It is guaranteed that the sum of over all test cases does not exceed .
Output
For each test case, on the first line print the number — the minimum time Divan will spend walking.
On the second line print the sequence of integers, where () is the selected coordinate of the -th building. It can be shown that an optimal answer exists with coordinates not exceeding .
If there are multiple answers, print any of them.
Note
Let's look at the first example.
Divan will visit the first building times, the second times and the third times. Then one of the optimal solution will be as follows:
- the headquarters is located in ;
- : Divan will spend $2 \cdot |x_0-x_1| \cdot a_1 = 2 \cdot |2-4| \cdot 1 = 4$ minutes walking to the first building;
- : Divan will spend $2 \cdot |x_0-x_2| \cdot a_2 = 2 \cdot |2-1| \cdot 2 = 4$ minutes walking to the second building;
- : Divan will spend $2 \cdot |x_0-x_3| \cdot a_3 = 2 \cdot |2-3| \cdot 3 = 6$ minutes walking to the third building.
In total, Divan will spend minutes. It can be shown that it is impossible to arrange buildings so that the businessman spends less time.
Among others, , are also correct answers for the first example.
Samples
4
3
1 2 3
5
3 8 10 6 1
5
1 1 1 1 1
1
0
14
2 4 1 3
78
1 -1 0 2 3 4
18
3 6 1 5 2 4
0
1 2
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |