728x90
์ต๋๊ฐ ์์ด๋์ด
๋์ ํ์ด
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(int argc, char** argv)
{
int test_case;
int T;
int height;
// freopen("sample_input.txt", "r", stdin);
for(test_case = 1; test_case <= 10; ++test_case)
{
int answer = 0;
vector<int> h;
cin >> T;
for (int i = 0; i < T; ++i){
cin >> height;
h.push_back(height);
}
for (int i = 2; i < T-2; ++i){
if(h[i]==0)
continue;
if(h[i]>h[i-1] && h[i]>h[i+1]){
if(h[i]>h[i-2] && h[i]>h[i+2]){
int m = max({h[i - 1], h[i - 2], h[i + 1], h[i + 2]});
answer += (h[i] - m);
}
}
}
cout << "#" << test_case << " " << answer << "\n";
}
return 0;//์ ์์ข
๋ฃ์ ๋ฐ๋์ 0์ ๋ฆฌํดํด์ผํฉ๋๋ค.
}
728x90
'๐ ์๊ณ ๋ฆฌ์ฆ' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[C++/SWEA] 1208. [S/W ๋ฌธ์ ํด๊ฒฐ ๊ธฐ๋ณธ] 1์ผ์ฐจ - Flatten (D3) (0) | 2024.11.16 |
---|---|
[C++/SWEA] 1859. ๋ฐฑ๋ง ์ฅ์ ํ๋ก์ ํธ (D2) (0) | 2024.11.16 |
[C++/SWEA] 21425. += (D2) (0) | 2024.11.16 |
[C++/SWEA] 1215. [S/W ๋ฌธ์ ํด๊ฒฐ ๊ธฐ๋ณธ] 3์ผ์ฐจ - ํ๋ฌธ1 (D3) (0) | 2024.11.16 |