import
java.util.Scanner;
class
Solution {
static
int
Answer;
public
static
void
main(String args[])
throws
Exception {
Scanner sc =
new
Scanner(System.in);
for
(
int
T=
1
; T <=
10
; T++) {
int
size = sc.nextInt();
int
[] inputList =
new
int
[size];
for
(
int
i=
0
; i <size ;i++) {
inputList[i] = sc.nextInt();
}
// i 번째 조망권 (양옆 2이 배열범위에 벗어나지 않았을 떄 가정)
int
viewCount =
0
;
for
(
int
i=
0
; i<size ; i++) {
int
left_2 = i-
2
>=
0
? inputList[i-
2
] :
0
;
int
left_1 = i-
1
>=
0
? inputList[i-
1
] :
0
;
int
right_1 = i +
1
< size ? inputList[i+
1
] :
0
;
int
right_2 = i +
2
< size ? inputList[i+
2
] :
0
;
int
max = left_2;
if
(max < left_1) {max = left_1;}
if
(max < right_1) {max = right_1;}
if
(max < right_2) {max = right_2;}
viewCount += inputList[i] > max ? inputList[i]-max :
0
;
}
System.out.println(String.format(
"#%d %d"
, T, viewCount) );
}
}
}
'Knowledge > 알고리즘' 카테고리의 다른 글
1218. [S/W 문제해결 기본] 4일차 - 괄호 짝짓기 (0) | 2017.09.30 |
---|---|
1216. [S/W 문제해결 기본] 3일차 - 회문2 (0) | 2017.09.30 |
1226. [S/W 문제해결 기본] 7일차 - 미로1 (0) | 2017.09.30 |
1208. [S/W 문제해결 기본] 1일차 - Flatten (0) | 2017.09.30 |
백준 1024번 수열의 합 (0) | 2017.08.26 |