๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

๐Ÿ“ ์•Œ๊ณ ๋ฆฌ์ฆ˜

[C++/SWEA] 1208. [S/W ๋ฌธ์ œํ•ด๊ฒฐ ๊ธฐ๋ณธ] 1์ผ์ฐจ - Flatten (D3)

728x90

 

https://swexpertacademy.com/main/code/problem/problemDetail.do?problemLevel=3&contestProbId=AV139KOaABgCFAYh&categoryId=AV139KOaABgCFAYh&categoryType=CODE&problemTitle=&orderBy=RECOMMEND_COUNT&selectCodeLang=CCPP&select-1=3&pageSize=10&pageIndex=1

 

SW Expert Academy

SW ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์—ญ๋Ÿ‰ ๊ฐ•ํ™”์— ๋„์›€์ด ๋˜๋Š” ๋‹ค์–‘ํ•œ ํ•™์Šต ์ปจํ…์ธ ๋ฅผ ํ™•์ธํ•˜์„ธ์š”!

swexpertacademy.com

 

ez

swea๋Š” ๋‚œ์ด๋„๊ฐ€ ๋“ค์‘ฅ๋‚ ์‘ฅ์ด๋ผ๋”๋‹ˆ ๋งž๋Š” ๋ง์ธ ๊ฒƒ ๊ฐ™๋‹ค

์ด ๋ฌธ์ œ๋Š” D2๋ณด๋‹ค ์‰ฌ์šด๋“ฏ

 

๋‚˜์˜ ํ’€์ด

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

int main(int argc, char** argv)
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	// freopen("input (3).txt", "r", stdin);
	int test_case;
	int T = 10;
	int dump = 0;
	int num = 0;
	int answer = 0;
	// cin >> T;
	for(test_case = 1; test_case <= T; ++test_case)
	{
		vector<int> v;
		cin >> dump;
		for (int i = 0; i < 100; ++i){
			cin >> num;
			v.push_back(num);
		}
		for (int i = 0; i < dump; ++i){
			int maxi = max_element(v.begin(), v.end()) - v.begin();
			int mini = min_element(v.begin(), v.end()) - v.begin();
			v[maxi] -= 1;
			v[mini] += 1;
		}
		answer = *max_element(v.begin(), v.end()) - *min_element(v.begin(), v.end());
		cout << "#" << test_case << " " << answer << "\n";
	}
	return 0;
}

 

 

728x90