Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

22.03.15 - [BOJ] 2217. 로프 #229

Closed
suhyunsim opened this issue Mar 15, 2022 · 0 comments
Closed

22.03.15 - [BOJ] 2217. 로프 #229

suhyunsim opened this issue Mar 15, 2022 · 0 comments
Assignees
Labels
그리디 그리디 알고리즘 성공 맞은 문제 실버 BOJ - 실버

Comments

@suhyunsim
Copy link
Owner

문제

핵심 아이디어

  • 일단 사용할 로프의 개수를 결정했다고 생각 -> 어떤 로프를 선택할까?
    • -> 당연히 가장 최대 중량이 큰 로프 k개를 선택
    • 귀류법으로 증명: 최대 중량 순으로 선택하지 않았을 때 최대 중량이 가장 낮은 로프의 중량은 가장 최대 중량이 큰 로프들을 선택했을 때보다 클 수 없음
    • 로프의 최대 중량을 결정, 로프를 k개 고른다면 => w[n - k] * k

어려운 점, 실수

풀이

package main.java.com.poogle.BOJ.Q2217;

import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] weight = new int[n];
        for (int i = 0; i < n; i++) {
            weight[i] = sc.nextInt();
        }
        Arrays.sort(weight);
        int answer = 0;
        for (int i = 1; i <= n; i++) {
            answer = Math.max(answer, weight[n - i] * i);
        }
        System.out.println(answer);
    }
}
@suhyunsim suhyunsim added 성공 맞은 문제 실버 BOJ - 실버 그리디 그리디 알고리즘 labels Mar 15, 2022
@suhyunsim suhyunsim self-assigned this Mar 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
그리디 그리디 알고리즘 성공 맞은 문제 실버 BOJ - 실버
Projects
None yet
Development

No branches or pull requests

1 participant