[Greedy]217号-ケーブル(33日目)
5300 ワード
#include <iostream>
//memset 쓰기 위한 cstring
#include <cstring>
//sort 쓰기 위한 algorithm
#include <algorithm>
using namespace std;
int main(){
//로프의 개수 입력
int n;
cin >> n;
//로프의 개수만큼 로프 중량값 저장 1차원 배열 동적 할당 후 0으로 초기화
int *rope = new int[n];
memset(rope, 0, sizeof(n));
//로프 중량값 입력
for(int i=0; i<n; i++){
cin >> rope[i];
}
//사용된 로프의 개수를 세는 변수
int rope_cnt = 1;
//중량 최대값 저장 변수
int weight = 0;
//로프들을 중량값 기준으로 내림차순 정렬
sort(rope, rope+n, greater<int>());
//모든 로프에 대해서
for(int j=0; j<n; j++){
//해당 로프 중량 최대값 x 총 로프 개수가 중량 최대값보다 크면 중량값 업데이트
if(rope_cnt * rope[j] >= weight){
weight = rope_cnt * rope[j];
}
//사용된 로프 개수 추가
rope_cnt++;
}
//저장된 중량 최대값 출력
cout << weight;
}
Reference
この問題について([Greedy]217号-ケーブル(33日目)), 我々は、より多くの情報をここで見つけました https://velog.io/@bobsiunn/Greedy-2217번-로프33일차-6af7t6zbテキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol