# 1008. Elevator (20)

64人阅读 评论(0)

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

#include<stdio.h>
#define N 100
int main(){
int a[N],n,i,second=0;
scanf("%d",&n);
a[0]=0;
for(i=1;i<=n;i++){
scanf("%d",&a[i]);
if(a[i]>a[i-1])second+=6*(a[i]-a[i-1]);
else second+=4*(a[i-1]-a[i]);
}
second+=n*5;
printf("%d",second);
}
0
0

* 以上用户言论只代表其个人观点，不代表CSDN网站的观点或立场
个人资料
• 访问：41872次
• 积分：2764
• 等级：
• 排名：第13028名
• 原创：247篇
• 转载：6篇
• 译文：0篇
• 评论：8条
阅读排行
评论排行
最新评论