mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-10 18:48:13 +08:00
47 lines
1.9 KiB
HTML
47 lines
1.9 KiB
HTML
<p>There are an infinite amount of bags on a number line, one bag for each coordinate. Some of these bags contain coins.</p>
|
|
|
|
<p>You are given a 2D array <code>coins</code>, where <code>coins[i] = [l<sub>i</sub>, r<sub>i</sub>, c<sub>i</sub>]</code> denotes that every bag from <code>l<sub>i</sub></code> to <code>r<sub>i</sub></code> contains <code>c<sub>i</sub></code> coins.</p>
|
|
|
|
<p>The segments that <code>coins</code> contain are non-overlapping.</p>
|
|
|
|
<p>You are also given an integer <code>k</code>.</p>
|
|
|
|
<p>Return the <strong>maximum</strong> amount of coins you can obtain by collecting <code>k</code> consecutive bags.</p>
|
|
|
|
<p> </p>
|
|
<p><strong class="example">Example 1:</strong></p>
|
|
|
|
<div class="example-block">
|
|
<p><strong>Input:</strong> <span class="example-io">coins = [[8,10,1],[1,3,2],[5,6,4]], k = 4</span></p>
|
|
|
|
<p><strong>Output:</strong> <span class="example-io">10</span></p>
|
|
|
|
<p><strong>Explanation:</strong></p>
|
|
|
|
<p>Selecting bags at positions <code>[3, 4, 5, 6]</code> gives the maximum number of coins: <code>2 + 0 + 4 + 4 = 10</code>.</p>
|
|
</div>
|
|
|
|
<p><strong class="example">Example 2:</strong></p>
|
|
|
|
<div class="example-block">
|
|
<p><strong>Input:</strong> <span class="example-io">coins = [[1,10,3]], k = 2</span></p>
|
|
|
|
<p><strong>Output:</strong> <span class="example-io">6</span></p>
|
|
|
|
<p><strong>Explanation:</strong></p>
|
|
|
|
<p>Selecting bags at positions <code>[1, 2]</code> gives the maximum number of coins: <code>3 + 3 = 6</code>.</p>
|
|
</div>
|
|
|
|
<p> </p>
|
|
<p><strong>Constraints:</strong></p>
|
|
|
|
<ul>
|
|
<li><code>1 <= coins.length <= 10<sup>5</sup></code></li>
|
|
<li><code>1 <= k <= 10<sup>9</sup></code></li>
|
|
<li><code>coins[i] == [l<sub>i</sub>, r<sub>i</sub>, c<sub>i</sub>]</code></li>
|
|
<li><code>1 <= l<sub>i</sub> <= r<sub>i</sub> <= 10<sup>9</sup></code></li>
|
|
<li><code>1 <= c<sub>i</sub> <= 1000</code></li>
|
|
<li>The given segments are non-overlapping.</li>
|
|
</ul>
|