알고리즘/SWEA

[SWEA 1206] View

히더 2018. 8. 5. 15:18

출처 : https://www.swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV134DPqAA8CFAYh#none


#include <iostream>

#include <algorithm>

#include <memory.h>

using namespace std;


int N, arr[1000], result;


int main()

{

int t = 1, T = 10;

while (T--)

{

result = 0; memset(arr, 0, sizeof(arr));

cin >> N;

for (int i = 0; i < N; i++)cin >> arr[i];

for (int i = 2; i < N - 2; i++)

{

int tmp = arr[i] - max(max(arr[i - 2], arr[i - 1]), max(arr[i + 1], arr[i + 2]));

if (tmp > 0) result += tmp;

}


cout << "#" << t++ << " " << result << endl;

}


return 0;

}