A1215 | [COCI-2010_2011-olympiad]#3 RIJEKA
来源COCI
时间限制1s
内存限制128MB
通过 / 提交0/0
题目描述
In the far away land there is a big river and a number of villages beside it. Villages are numbered 0 through M, in order along the river. Distance bewteen consecutive villages is exactly 1 mile.
Mirko lives in the village marked with
0. He is in the business of transporting people between villages with his boat. Today, Mirko will travel from his village to village M, and he will also transport some people along the way.
There are N people that wish to travel today, and for each of them we know their starting point as well as their destination. Mirko's boat can accommodate as many people as needed.
Let's say for example that person A is traveling from village 2 to village 8, and B from village 6 to village
4. Mirko will, as always, start from his village 0, pick up A at village 2, pickup B at 6, go back to 4 and leave B there, proceed to village 8, leave A there, and then continue to his final destination, village M. This scenario is given in the first test case below.
Write a program that will find the minimum number of miles that Mirko must travel in order to transport everyone to their destinations and reach village M at the end.
Mirko lives in the village marked with
0. He is in the business of transporting people between villages with his boat. Today, Mirko will travel from his village to village M, and he will also transport some people along the way.
There are N people that wish to travel today, and for each of them we know their starting point as well as their destination. Mirko's boat can accommodate as many people as needed.
Let's say for example that person A is traveling from village 2 to village 8, and B from village 6 to village
4. Mirko will, as always, start from his village 0, pick up A at village 2, pickup B at 6, go back to 4 and leave B there, proceed to village 8, leave A there, and then continue to his final destination, village M. This scenario is given in the first test case below.
Write a program that will find the minimum number of miles that Mirko must travel in order to transport everyone to their destinations and reach village M at the end.
输入格式
The first line of input contains integers N and M (N ≤ 300 000, 3 ≤ M ≤ 109).
The following N lines contain two integers, starting point and destination for each villagers that want's to travel today. These number will be in range 0 to M.
The following N lines contain two integers, starting point and destination for each villagers that want's to travel today. These number will be in range 0 to M.
输出格式
Output the minimum number of miles that Mirko must travel.
输入输出样例
输入 #1
2 10 2 8 6 4
输出 #1
14
输入 #2
8 15 1 12 3 1 3 9 4 2 7 13 12 11 14 11 14 13
输出 #2
27
In test cases worth a total of 40% points, N ≤ 5000 will hold.
In test cases worth a total of 50% points, M ≤ 2000000 will hold.
In test cases worth a total of 50% points, M ≤ 2000000 will hold.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted