Coding Test - cpp/Greedy
[백준 2217: 로프] - C++
에드윈H
2021. 1. 29. 15:51
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
int N;
cin >> N;
int arr[100000];
for (int i = 0; i < N; i++)
{
cin >> arr[i];
}
sort(arr, arr + N, greater<int>()); //내림차순 정렬
long long result = 0;
for (int i = 0; i < N; i++)
{
long long sum = arr[i] * (i + 1);
if (sum > result)
{
result = sum;
}
}
cout << result << endl;
return 0;
}