Baekjoon 2217
로프


QUESTION ❔



CODE ⌨️

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

using namespace std;

int N, r;
vector<int> rope;
int temp;
int maxcost = 0;

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

	cin >> N;

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

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

	for (int i = 0; i < N; i++)
	{
		temp = rope[i] * (i + 1);

		if (temp > maxcost)
		{
			maxcost = temp;
		}
	}

	cout << maxcost << "\n";

	return 0;
}



RESULT 💛



SIMPLE DISCUSSION ✏️

Greedy 알고리즘 관련 문제였다.



SOURCE 💎

Baekjoon_Link 👈 Click here


*****
NOT A TALENT ❎ NOT GIVING UP ✅
CopyRight ⓒ 2022 DCherish All Rights Reserved.