백준 14487 c++ : Greedy algorithms

magicdrill·2025년 2월 18일
0

백준 문제풀이

목록 보기
553/655

백준 14487 c++ : Greedy algorithms

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

void input_city(vector<int>& city) {
	int n, i, v;

	cin >> n;
	for (i = 0; i < n; i++) {
		cin >> v;
		city.push_back(v);
	}

	return;
}

int find_answer(vector<int>& city) {
	int answer = 0, i;

	sort(city.begin(), city.end());
	for (i = 0; i < city.size() - 1; i++) {
		answer += city[i];
	}

	return answer;
}

int main(void) {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	vector<int> city;

	input_city(city);
	cout << find_answer(city) << "\n";

	return 0;
}

0개의 댓글