Skip to main content

Practice · 3 of 5

Minimum Total Waiting Time

CHALLENGE
Difficulty: beginner+25 XP

**Description:** n customers with service times wait in a single queue. You choose the order. A customer's waiting time is the sum of service times of everyone served before them. Minimize the **total** waiting time. **Input:** Line 1: n (1 ≤ n ≤ 10^5). Line 2: n service times (1 ≤ each ≤ 10^9). **Output:** One integer — the minimal total waiting time (fits in long long). **Example:** 3 / 4 1 3 → order 1, 3, 4 → waits 0, 1, 4 → total 5.

Back to lesson: Practice: Greedy Set