A15032 | Even Split
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
A revolution has recently happened in Segmentland. The new government is committed to equality, and they hired you to help with land redistribution in the country.
Segmentland is a segment of length $l$ kilometers, with the capital in one of its ends. There are $n$ citizens in Segmentland, the home of $i$ -th citizen is located at the point $a_i$ kilometers from the capital. No two homes are located at the same point. Each citizen should receive a segment of positive length with ends at integer distances from the capital that contains her home. The union of these segments should be the whole of Segmentland, and they should not have common points besides their ends. To ensure equality, the difference between the lengths of the longest and the shortest segments should be as small as possible.
Segmentland is a segment of length $l$ kilometers, with the capital in one of its ends. There are $n$ citizens in Segmentland, the home of $i$ -th citizen is located at the point $a_i$ kilometers from the capital. No two homes are located at the same point. Each citizen should receive a segment of positive length with ends at integer distances from the capital that contains her home. The union of these segments should be the whole of Segmentland, and they should not have common points besides their ends. To ensure equality, the difference between the lengths of the longest and the shortest segments should be as small as possible.
输入格式
The first line of the input contains two integers $l$ and $n$ ( $2 \leq l \leq 10^9; 1 \leq n \leq 10^5$ ).
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ( $0 < a_1 < a_2 < \dots < a_n < l$ ).
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ( $0 < a_1 < a_2 < \dots < a_n < l$ ).
输出格式
Output $n$ pairs of numbers $s_i, f_i$ ( $0 \leq s_i < f_i \leq l$ ), one pair per line. The pair on $i$ -th line denotes the ends of the $[s_i, f_i]$ segment that $i$ -th citizen receives.
If there are many possible arrangements with the same difference between the lengths of the longest and the shortest segments, you can output any of them.
If there are many possible arrangements with the same difference between the lengths of the longest and the shortest segments, you can output any of them.
输入输出样例
输入 #1
6 3 1 3 5
输出 #1
0 2 2 4 4 6
输入 #2
10 2 1 2
输出 #2
0 2 2 10
In the first example, it is possible to make all segments equal. Viva la revolucion!
In the second example, citizens live close to the capital, so the length of the shortest segment is 2 and the length of the longest segment is 8.

In the second example, citizens live close to the capital, so the length of the shortest segment is 2 and the length of the longest segment is 8.

C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted