출처
SW Expert Academy
SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!
swexpertacademy.com
풀이
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
int N = 0;
int result = 0;
int solution(int* buildings) {
int cnt = 0;
for (int i = 2; i < N-2; i++) {
int near = max(max(buildings[i - 2], buildings[i - 1]),max(buildings[i + 1], buildings[i + 2]));
if (near < buildings[i]){
cnt += buildings[i] - near;
}
}
return cnt;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
for (int i = 1; i < 11; i++) {
cin >> N;
int buildings[1001];
for (int j = 0; j < N; j++) {
cin >> buildings[j];
}
result = solution(buildings);
cout << "#" << i << " " << result << endl;
}
}
반응형
'알고리즘' 카테고리의 다른 글
[C++] SWEA 행렬정렬 (1) | 2024.11.13 |
---|---|
[C++] SWEA [모의 SW 역량테스트] 미생물 격리 (1) | 2024.11.13 |
[Codility][Kotlin] MissingInteger (0) | 2024.10.07 |
[Codility][Kotlin]PermCheck (1) | 2024.10.04 |
[Codility][Kotlin] FrogRiverOne (0) | 2024.10.04 |