Skip to content

Latest commit

ย 

History

History
49 lines (35 loc) ยท 982 Bytes

File metadata and controls

49 lines (35 loc) ยท 982 Bytes

๋ฌธ์ œ

๋กœํ”„

๋ฌธ์ œ ์›๋ณธ

๋ฌธ์ œ์˜ ์›๋ณธ์€ ์—ฌ๊ธฐ์„œ ํ™•์ธํ•˜์„ธ์š”.

๋ถ„๋ฅ˜

  • ๊ทธ๋ฆฌ๋”” ์•Œ๊ณ ๋ฆฌ์ฆ˜

ํ’€์ด

๋กœํ”„์˜ ์ตœ๋Œ€ ์ค‘๋ฅ ์„ ๊ธฐ์ค€์œผ๋กœ ๋‚ด๋ฆผ ์ฐจ์ˆœ์œผ๋กœ ์ •๋ ฌํ•œ ํ›„, i๋ฒˆ์งธ์˜ i๋ฒˆ์งธ์˜ ์ค‘๋Ÿ‰ x (i+1)์„ ํ†ตํ•ด ์ตœ๋Œ€ ์ค‘๋Ÿ‰์„ ๊ตฌํ•œ๋‹ค. ์ด๋ ‡๊ฒŒ ๊ตฌํ•ด์ง„ ์ค‘๋Ÿ‰์ด ์ „์— ๊ตฌํ•œ ์ค‘๋Ÿ‰๋ณด๋‹ค ํฐ๊ฒฝ์šฐ ์ตœ๋Œ€ ์ค‘๋Ÿ‰์„ ์—…๋ฐ์ดํŠธ ํ•œ๋‹ค.

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

using namespace std;


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

    int N;
    cin >> N;

    vector<int> ropes(N);

    for (int i = 0; i < N; i++) {
        cin >> ropes[i];
    }

    sort(ropes.begin(), ropes.end(), greater<int>());

    long long max = 0;
    for (int i = 0; i < N; i++) {
        long long sum = ropes[i] * (i + 1);
        if (max < sum) {
            max = sum;
        }
    }

    cout << max;

    return 0;
}