Skip to main content

Practice · 1 of 4

Sprint A — No Two Adjacent (SELF-TIMED 15)

CHALLENGE
Difficulty: advanced+25 XP

**SELF-TIMED: 15 minutes.** Read, recognize, implement, verify. If the clock beats you, stop and study the editorial cycle — that is the training. **Bài toán.** Given n non-negative integers, choose a subset of positions with **no two adjacent** (positions i and i+1 cannot both be chosen), maximizing the sum of chosen values. **Constraints:** 1 ≤ n ≤ 200000; 0 ≤ a[i] ≤ 1000. **Input:** line 1: n; line 2: n values. **Output:** one integer — the maximum sum.

Back to lesson: Practice: Contest Sprints — Four Clocks