The highest building in We City have only one elevator. A request list is made to with N positive numbers. The numbers denote at which floors the elevator would stop, in specified order. It costs 6 seconds to move the elevator-one floor, and 4 seconds to move-down-one floor. The elevator would stay for 5 seconds on each stop.
For a given request list, you is 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 having to return to the ground floor when the requests was Fu Lfilled.
Input Specification:
Each input file contains the one test case. Each case contains a positive an integer n, followed by N positive numbers. All the numbers in the input is less than 100.
Output Specification:
For each test case, print the total time of a single line.
Sample Input:
3 2 3 1
Sample Output:
41
#include <stdio.h>
#include <string.h>
#include <math.h>
int main ()
{
int n,a[110],i,j,sum=0,t;
scanf ("%d", &n);
a[0]=0;
for (i=1;i<=n;i++)
{
scanf ("%d", &a[i]);
if (A[i]>a[i-1])
{
T=A[I]-A[I-1];
Sum+=6*t;
}
Else
{
T=a[i-1]-a[i];
Sum+=4*t;
}
sum+=5;
}
printf ("%d\n", sum);
return 0;
}
1008. Elevator (20)