50041. Mountains

難度:2/5

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <stdio.h>
#include <stdlib.h>

int main(){
int n;
long long ans = 0;
int h1, h2, prev_height, prev_h, now_h;

scanf("%d", &n);
scanf("%d %d", &h1, &h2);
prev_h = h2;
prev_height = h2 - h1;
if(prev_height > 0) ans += (3 * prev_height);
if(prev_height < 0) ans += (-2 * prev_height);

for(int i = 2; i < n; i++){
scanf("%d", &now_h);
int now_height = now_h - prev_h;
if(now_height > 0){
if(prev_height > 0) ans += (4 * now_height);
else ans += (3 * now_height);
}
else{
if(prev_height > 0) ans += (-3 * now_height);
else ans += (-2 * now_height);
}

prev_h = now_h;
prev_height = now_height;
}
printf("%lld\n", ans);
}


50041. Mountains
https://aaronlin1229.github.io/judgegirl_50041/
Author
Akizumi
Posted on
July 17, 2023
Licensed under