CF983C.Elevator
提高+/省选-
通过率:0%
时间限制:3.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You work in a big office. It is a 9 floor building with an elevator that can accommodate up to 4 people. It is your responsibility to manage this elevator.
Today you are late, so there are queues on some floors already. For each person you know the floor where he currently is and the floor he wants to reach. Also, you know the order in which people came to the elevator.
According to the company's rules, if an employee comes to the elevator earlier than another one, he has to enter the elevator earlier too (even if these employees stay on different floors). Note that the employees are allowed to leave the elevator in arbitrary order.
The elevator has two commands:
- Go up or down one floor. The movement takes 1 second.
- Open the doors on the current floor. During this operation all the employees who have reached their destination get out of the elevator. Then all the employees on the floor get in the elevator in the order they are queued up while it doesn't contradict the company's rules and there is enough space in the elevator. Each employee spends 1 second to get inside and outside the elevator.
Initially the elevator is empty and is located on the floor 1.
You are interested what is the minimum possible time you need to spend to deliver all the employees to their destination. It is not necessary to return the elevator to the floor 1.
你在一家大型办公室工作。这是一栋9层高的建筑,配备一部最多可容纳4人的电梯,而你负责管理这部电梯。
今天你迟到了,因此某些楼层已经排起了队列。对于每个人,你知道他当前所在的楼层以及他想要到达的楼层。此外,你还知道人们到达电梯的先后顺序。
根据公司规定,如果一名员工比另一名员工更早到达电梯,那么他也必须更早进入电梯(即使这些员工位于不同的楼层)。注意,员工离开电梯的顺序可以是任意的。
电梯有两种指令:
- 向上或向下移动一层。每次移动耗时1秒。
- 在当前楼层打开电梯门。在此操作期间,所有已到达目的地的员工将离开电梯。随后,该楼层上的所有员工将按照排队顺序依次进入电梯,前提是不违反公司规定且电梯内仍有足够空间。每位员工进出电梯各需耗时1秒。
初始状态下,电梯为空,且位于1楼。
你希望知道:将所有员工运送至各自目的地所需的最短时间是多少?电梯最终无需返回1楼。
输入格式
The first line contains an integer n (1 ≤ n ≤ 2000) — the number of employees.
The i-th of the next n lines contains two integers a__i and b__i (1 ≤ a__i, b__i ≤ 9, a__i ≠ b__i) — the floor on which an employee initially is, and the floor he wants to reach.
The employees are given in the order they came to the elevator.
第一行包含一个整数 n(1≤n≤2000)—— 员工人数。
接下来的 n 行中,第 i 行包含两个整数 ai 和 bi(1≤ai,bi≤9,且 ai=bi)—— 分别表示第 i 名员工初始所在的楼层以及他想要到达的楼层。
员工按其到达电梯的顺序给出。
输出格式
Print a single integer — the minimal possible time in seconds.
输出一个整数——以秒为单位的最短可能时间。
输入输出样例
输入#1
2 3 5 5 3
输出#1
10
输入#2
2 5 3 3 5
输出#2
12
说明/提示
Explaination for the first sample
t = 0
t = 2
t = 3
t = 5
t = 6
t = 7
t = 9
t = 10
第一个样例的解释
t = 0
t = 2
t = 3
t = 5
t = 6
t = 7
t = 9
t = 10
输入解题思路,AI测评打分。不知道怎么写?