Skip to main content

Practice · 1 of 6

Final 1: The Showcase

CHALLENGE
Difficulty: advanced+25 XP

**Bài toán.** A shop displays n items in a row; item i has value a[i]. A window is a contiguous set of items containing **at most k distinct values** (distinct by value, not by position). Find the maximum total value of a non-empty window. **Constraints:** 1 ≤ n ≤ 200000; 1 ≤ k ≤ n; 1 ≤ a[i] ≤ 5000. **Input:** line 1: n, k; line 2: n values. **Output:** one integer.

Back to lesson: Practice: The Final Pack