A9777 | Berland Local Positioning System
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
The first line contains integer $n$ ( $2<=n<=2·10^{5}$ ) — the number of stops.
The second line contains $n$ integers ( $1<=a_{i}<=10^{9}$ ) — the distance from the $i$ -th stop to the central square. The numbers in the second line go in the increasing order.
The third line contains integer $m$ ( $1<=m<=4·10^{5}$ ) — the number of stops the bus visited on some segment of the path.
The fourth line contains $m$ integers ( $1<=b_{i}<=n$ ) — the sorted list of numbers of the stops visited by the bus on the segment of the path. The number of a stop occurs as many times as it was visited by a bus.
It is guaranteed that the query corresponds to some segment of the path.
The second line contains $n$ integers ( $1<=a_{i}<=10^{9}$ ) — the distance from the $i$ -th stop to the central square. The numbers in the second line go in the increasing order.
The third line contains integer $m$ ( $1<=m<=4·10^{5}$ ) — the number of stops the bus visited on some segment of the path.
The fourth line contains $m$ integers ( $1<=b_{i}<=n$ ) — the sorted list of numbers of the stops visited by the bus on the segment of the path. The number of a stop occurs as many times as it was visited by a bus.
It is guaranteed that the query corresponds to some segment of the path.
输入格式
In the single line please print the distance covered by a bus. If it is impossible to determine it unambiguously, print $-1$ .
输出格式
The first test from the statement demonstrates the first example shown in the statement of the problem.
The second test from the statement demonstrates the second example shown in the statement of the problem.
In the third sample there are two possible paths that have distinct lengths, consequently, the sought length of the segment isn't defined uniquely.
In the fourth sample, even though two distinct paths correspond to the query, they have the same lengths, so the sought length of the segment is defined uniquely.
The second test from the statement demonstrates the second example shown in the statement of the problem.
In the third sample there are two possible paths that have distinct lengths, consequently, the sought length of the segment isn't defined uniquely.
In the fourth sample, even though two distinct paths correspond to the query, they have the same lengths, so the sought length of the segment is defined uniquely.
输入输出样例
输入 #1
6 2 3 5 7 11 13 5 3 4 5 5 6
输出 #1
10
输入 #2
6 2 3 5 7 11 13 9 1 2 2 3 3 4 5 5 6
输出 #2
16
输入 #3
3 10 200 300 4 1 2 2 3
输出 #3
-1
输入 #4
3 1 2 3 4 1 2 2 3
输出 #4
3
The first test from the statement demonstrates the first example shown in the statement of the problem.
The second test from the statement demonstrates the second example shown in the statement of the problem.
In the third sample there are two possible paths that have distinct lengths, consequently, the sought length of the segment isn't defined uniquely.
In the fourth sample, even though two distinct paths correspond to the query, they have the same lengths, so the sought length of the segment is defined uniquely.
The second test from the statement demonstrates the second example shown in the statement of the problem.
In the third sample there are two possible paths that have distinct lengths, consequently, the sought length of the segment isn't defined uniquely.
In the fourth sample, even though two distinct paths correspond to the query, they have the same lengths, so the sought length of the segment is defined uniquely.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted