Elevator
Total Submission(s): 74013 Accepted Submission(s): 40781
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.
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
int n,a[101];
while(scanf("%d",&n)!=EOF&&n){
for(int i=0;i<n;i++){
scanf("%d",&a[i]);
}
int sum=(a[0]-0)*6+5,m=a[0];
if(n==1){
sum=sum;
}else{
for(int i=1;i<n;i++){
if(a[i]>m){
sum+=(a[i]-m)*6+5;
m=a[i];
}
else if(a[i]<m){
sum+=(m-a[i])*4+5;
m=a[i];
}else{
sum+=5;
}
}
}
printf("%d\n",sum);
}
return 0;
}