Skip to main content

Practice · 2 of 4

Sprint B — Closest Subset Sum (SELF-TIMED 20)

CHALLENGE
Difficulty: advanced+25 XP

**SELF-TIMED: 20 minutes.** The constraint column decides the algorithm in the first minute; the rest is careful delivery. **Bài toán.** Given n items with values a[i] and a target S, choose any subset (possibly empty) minimizing |sum − S|. On ties, output the **smaller** sum. Print the chosen sum. **Constraints:** 1 ≤ n ≤ 15; 1 ≤ a[i] ≤ 10^9; 1 ≤ S ≤ 10^9. **Input:** line 1: n and S; line 2: n values. **Output:** one integer — the chosen subset sum.

Back to lesson: Practice: Contest Sprints — Four Clocks