Created
January 5, 2019 10:35
-
-
Save fpdjsns/0b45dd9a83490ad5a88de8be9dbed284 to your computer and use it in GitHub Desktop.
[SW Expert Academy] 1206. [S/W 문제해결 기본] 1일차 - View : https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV134DPqAA8CFAYh&categoryId=AV134DPqAA8CFAYh&categoryType=CODE
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<iostream> | |
#include<algorithm> | |
#include<vector> | |
using namespace std; | |
int main() { | |
for (int c = 1; c <= 10; c++) { | |
int ans = 0; | |
int n; | |
cin >> n; | |
// 왼쪽 2개, 체크1개, 오른쪽 2개 | |
vector<int> arr(5, 0); | |
for (int i = 0; i < n; i++) { | |
cin >> arr[i % 5]; | |
// check 2번째 전 | |
int checkInd = (i+ 3) % 5; | |
int maxNum = 0; | |
for (int j = 0; j < 5; j++) { | |
if (checkInd == j) continue; | |
maxNum = max(maxNum, arr[j]); | |
} | |
int diff = arr[checkInd] - maxNum; | |
ans += diff < 0 ? 0 : diff; | |
} | |
printf("#%d %d\n", c, ans); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment