Skip to main content

Practice · 2 of 6

Contest 1 — Problem B: The Ropes

CHALLENGE
Difficulty: advanced+25 XP

**Bài toán.** A climber has n ropes of lengths a[i]. Joining two ropes of lengths x and y costs x + y and produces one rope of length x + y. Join all ropes into one with minimum total cost; print that cost (one rope alone costs 0). **Constraints:** 1 ≤ n ≤ 200000; 1 ≤ a[i] ≤ 10^5. **Input:** line 1: n; line 2: n lengths. **Output:** one integer — the minimum total joining cost (fits in 64 bits).

Back to lesson: Practice: Mock Contests 1 & 2