The highest building in our city has only one elevator. A request list is made up with N positive numbers. The numbers denote at which floors the elevator will stop, in specified order. It costs 6 seconds to move the elevator up one floor, and 4 seconds to move down one floor. The elevator will stay for 5 seconds at each stop.

For a given request list, you are to compute the total time spent to fulfill the requests on the list. The elevator is on the 0th floor at the beginning and does not have to return to the ground floor when the requests are fulfilled.

Input Specification:

Each input file contains one test case. Each case contains a positive integer N, followed by N positive numbers. All the numbers in the input are less than 100.

Output Specification:

For each test case, print the total time on a single line.

Sample Input:

3 2 3 1

Sample Output:

41

题目翻译:

我们城市的最高建筑只有一部电梯,一个请求列表由N个正数组成。这个数字表示电梯将要停留的楼层,上移一层需要六秒钟,下移一层需要四秒钟,每次停留五秒钟。
对于一个给定的请求列表,你应该计算出总共的时间花费。电梯从第0层开始,在满足全部要求后并不要求返回

输入规范:

每个输入文件包含一个测试实例,每个实例包含一个正整数N,并紧接着跟上N个正数,所有输入的数字都小于100.

输出规范:

对于每个测试实例,在单独的一行中打印出总计时间。

代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
int n;
cin>>n;
int start =0,sums=0;//初始楼层
// 总共需要的数字
for(int i=0;i<n;i++){
int x;
cin>>x;
if(x>start)
sums=sums+(x-start)*6+5;
else
sums=sums+(start-x)*4+5;
start=x;
}
cout<<sums;
return 0;
}