๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
Algorithm ๐Ÿง‘๐Ÿป‍๐Ÿ’ป/๋ฐฑ์ค€(BOJ)

[๋ฐฑ์ค€,c++] 11399๋ฒˆ - ATM

by dkswnkk 2021. 10. 27.
 

11399๋ฒˆ: ATM

์ฒซ์งธ ์ค„์— ์‚ฌ๋žŒ์˜ ์ˆ˜ N(1 ≤ N ≤ 1,000)์ด ์ฃผ์–ด์ง„๋‹ค. ๋‘˜์งธ ์ค„์—๋Š” ๊ฐ ์‚ฌ๋žŒ์ด ๋ˆ์„ ์ธ์ถœํ•˜๋Š”๋ฐ ๊ฑธ๋ฆฌ๋Š” ์‹œ๊ฐ„ Pi๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. (1 ≤ Pi ≤ 1,000)

www.acmicpc.net

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

using namespace std;
vector<int>v;
int ans = 0;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int N; cin >> N;
    int cnt = N;
    for (int i = 0; i < N; i++) {
        int number; cin >> number;
        v.push_back(number);
    }
    sort(v.begin(), v.end());
    for (int i = 0; i < N; i++ ) {    
        ans+=v[i] * cnt;    // ex) N=5์ผ๋•Œ 1x5, 2x4, 3x3, 4x2, 5x1
        cnt--;
    }
    cout << ans;
}

๋Œ“๊ธ€