ATM

풀이

잘 생각해보면 정렬 문제로 풀 수 있다!

코드

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

int N;
int costs[1000];
int accSum = 0;
int answer = 0;

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

    cin >> N;
    for (int n = 0; n < N; n++)
        cin >> costs[n];
    sort(costs, costs + N);
    for (int i = 0; i < N; i++) {
        accSum += costs[i];
        answer += accSum;
    }
    cout << answer << '\n';
    return 0;
}

결과

결과메모리시간
맞았습니다!!2024 KB0 ms