그럴듯한 개발 블로그
Published 2023. 10. 5. 13:18
백준 2217 로프 c++ <algorithm>/백준
반응형

https://www.acmicpc.net/problem/2217

 

2217번: 로프

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

www.acmicpc.net

정렬그리디~

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <deque>
#include <unordered_set>
#include <cstring>
#include <utility>

using namespace	std;

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

	int num, res = 0;
	cin >> num;
	vector<int> rope;
	for (int i = 0; i < num; i++) {
		int input;
		cin >> input;
		rope.push_back(input);
	}
	sort(rope.begin(), rope.end());
	for (int i = 0; i < num; i++)
		res = max(res, rope[i] * (num - i));
	cout << res;
}
반응형

'<algorithm> > 백준' 카테고리의 다른 글

백준 2879 코딩은 예쁘게 c++  (1) 2023.10.09
백준 1026 보물 c++  (1) 2023.10.05
백준 11559 Puyo Puyo c++  (1) 2023.10.01
백준 1759 암호 만들기 c++  (0) 2023.09.24
백준 2195 문자열 복사 c++  (0) 2023.09.23
profile

그럴듯한 개발 블로그

@donghyk2

포스팅이 좋았다면 "좋아요❤️" 또는 "구독👍🏻" 해주세요!