Algorithm/백준

[백준] 2217번 : 로프

youngine 2021. 2. 10. 12:11
 

2217번: 로프

N(1 ≤ N ≤ 100,000)개의 로프가 있다. 이 로프를 이용하여 이런 저런 물체를 들어올릴 수 있다. 각각의 로프는 그 굵기나 길이가 다르기 때문에 들 수 있는 물체의 중량이 서로 다를 수도 있다. 하

www.acmicpc.net

 

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

int solution(vector<int>&rope) {
	int max = 0;
	sort(rope.begin(), rope.end());

	for (int i = 0;i < rope.size();i++) {
		int w = rope[i] * (rope.size() - i);
		if (max < w) max = w;
	}
	return max;
}

int main() {
	int n;
	vector<int>rope;

	cin >> n;
	for (int i = 0,r=0;i < n;i++) {
		cin >> r;
		rope.push_back(r);
	}

	cout<<solution(rope)<<'\n';
}