알고리즘

C++ 알고리즘 - 백준 11399 ATM

마루설아 2025. 1. 4. 19:48

https://www.acmicpc.net/problem/11399

 

#include <bits/stdc++.h>
#define endl "\n"

using namespace std;

int main(void) {
	/************** C++ Init **************/
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	/************** C++ Init **************/


	int input1, input2;
	int sum = 0;
	vector<int> v;
	cin >> input1;

	for (int i = 0; i < input1; i++) {
		cin >> input2;
		v.push_back(input2);
	}

	sort(v.begin(), v.end());

	sum = v[0];

	for (int i = 1; i < v.size(); i++) {
		v[i] += v[i - 1];
		sum += v[i];
	}

	cout << sum;
}