Algorithm

BOJ 2217 c++

최강훈 2020. 7. 17. 19:02

BOJ 2217 로프 c++

백준 2217번 로프 c++


#include <bits/stdc++.h>
using namespace std;

int n;
int arr[100005];
int d[100005];

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    cin >> n;
    fill(arr, arr + 100005, 100001);
    for (int i = 0; i < n; i++) {
        cin >> arr[i];
    }
    sort(arr, arr + n);
    int temp = n;
    for (int i = 0; i < n; i++) {
        d[i] = arr[i] * temp--;
    }
    cout << *max_element(d, d+100005);
}

분류 : 그리디