Skip to content

Conversation

@JHLEE325
Copy link
Contributor

🧷 문제 링크

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

🧭 풀이 시간

10분

👀 체감 난이도

✏️ 문제 설명

정렬된 카드묶음 2개를 합치는 경우 2개의 카드개수의 합 만큼 비교해야 함
카드 묶음들의 카드 갯수가 주어질 때 최소한의 비교로 전부 합치는 경우의 비교 횟수를 구하는 문제입니다.

🔍 풀이 방법

카드묶음들을합칠 때 적은 갯수의 카드묶음들을 반복해서 비교해야 총 비교횟수가 작아진다는 점을 파악했습니다.
입력받을 때 부터 priority 큐를 사용하여 자동으로 정렬되게 하였고 앞에서 2개씩 뽑아가며 연산을 수행했습니다.

for (int i = 0; i < n; i++) {
            q.add(Integer.parseInt(br.readLine()));
        }

        int result = 0;
        while (q.size() != 1) {
            int a = q.poll();
            int b = q.poll();
            result += a + b;
            q.add(a + b);
        }

⏳ 회고

적은 수를 많이 더해야 한다는 부분만 파악하면 우선순위큐만 알아도 풀리는 쉬운문제였습니다.

@JHLEE325 JHLEE325 added the success 👍 해설을 보지 않고 풀었을 때 label Jul 21, 2025
@ShinHeeEul ShinHeeEul merged commit 13a985d into main Jul 21, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

success 👍 해설을 보지 않고 풀었을 때

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants