ranges describes them: a triple ranges[i] = [l, r, c] means every house numbered from l to r inclusive holds c coins. The ranges in ranges do not overlap; houses outside every range hold no coins.
Pick length houses standing next to each other and take all their coins. Return the largest number of coins you can collect.ranges=[[2, 4, 3], [7, 8, 5], [12, 12, 9]], length=6 → 19
The best pick is houses 7 through 12: 5 + 5 from houses 7 and 8, nothing from 9–11 and 9 from house 12, 19 in total. Houses 2 through 7 give only 3 · 3 + 5 = 14.
ranges=[[5, 9, 2]], length=10 → 10
A window of 10 houses covers all of houses 5–9, each holding 2 coins: 5 · 2 = 10.
ranges=[[1, 3, 4], [4, 6, 1]], length=3 → 12
Houses 1–3 give 4 + 4 + 4 = 12; any window further right picks up houses with a single coin and ends up lower.
ranges.length ≤ 10⁵ranges[i] = [l, r, c], 1 ≤ l ≤ r ≤ 10⁹, 1 ≤ c ≤ 1000l, r] do not overlaplength ≤ 10⁹ranges=[[2, 4, 3], [7, 8, 5], [12, 12, 9]], length=6
19
Run checks the first 3 tests in your browser. Submit checks all 115 tests on the server, hidden ones included.