|
1 |
| -# [2907. Maximum Profitable Triplets With Increasing Prices I](https://leetcode.cn/problems/maximum-profitable-triplets-with-increasing-prices-i) |
| 1 | +# [2907. 价格递增的最大利润三元组 I](https://leetcode.cn/problems/maximum-profitable-triplets-with-increasing-prices-i) |
2 | 2 |
|
3 | 3 | [English Version](/solution/2900-2999/2907.Maximum%20Profitable%20Triplets%20With%20Increasing%20Prices%20I/README_EN.md)
|
4 | 4 |
|
5 | 5 | ## 题目描述
|
6 | 6 |
|
7 | 7 | <!-- 这里写题目描述 -->
|
8 | 8 |
|
9 |
| -<p>Given the <strong>0-indexed</strong> arrays <code>prices</code> and <code>profits</code> of length <code>n</code>. There are <code>n</code> items in an store where the <code>i<sup>th</sup></code> item has a price of <code>prices[i]</code> and a profit of <code>profits[i]</code>.</p> |
| 9 | +<p>给定两个长度为 <code>n</code> 的 <b>下标从 0 开始</b> 的数组 <code>prices</code> 和 <code>profits</code>。商店里有 <code>n</code> 件商品,其中第 <code>i</code> 件商品的价格为 <code>prices[i]</code>,利润为 <code>profits[i]</code>。</p> |
10 | 10 |
|
11 |
| -<p>We have to pick three items with the following condition:</p> |
| 11 | +<p>我们必须按照以下条件选择三件商品:</p> |
12 | 12 |
|
13 | 13 | <ul>
|
14 |
| - <li><code>prices[i] < prices[j] < prices[k]</code> where <code>i < j < k</code>.</li> |
| 14 | + <li><code>prices[i] < prices[j] < prices[k]</code>,其中 <code>i < j < k</code>。</li> |
15 | 15 | </ul>
|
16 | 16 |
|
17 |
| -<p>If we pick items with indices <code>i</code>, <code>j</code> and <code>k</code> satisfying the above condition, the profit would be <code>profits[i] + profits[j] + profits[k]</code>.</p> |
| 17 | +<p>如果我们选择满足上述条件的索引 <code>i</code>,<code>j</code> 和 <code>k</code> 的商品,那么利润就是 <code>profits[i] + profits[j] + profits[k]</code>。</p> |
18 | 18 |
|
19 |
| -<p>Return<em> the <strong>maximum profit</strong> we can get, and </em><code>-1</code><em> if it's not possible to pick three items with the given condition.</em></p> |
| 19 | +<p>返回我们能得到的最大利润,如果无法选择三件满足条件的商品,则返回 <code>-1</code>。</p> |
20 | 20 |
|
21 | 21 | <p> </p>
|
22 |
| -<p><strong class="example">Example 1:</strong></p> |
| 22 | + |
| 23 | +<p><strong class="example">示例 1:</strong></p> |
23 | 24 |
|
24 | 25 | <pre>
|
25 |
| -<strong>Input:</strong> prices = [10,2,3,4], profits = [100,2,7,10] |
26 |
| -<strong>Output:</strong> 19 |
27 |
| -<strong>Explanation:</strong> We can't pick the item with index i=0 since there are no indices j and k such that the condition holds. |
28 |
| -So the only triplet we can pick, are the items with indices 1, 2 and 3 and it's a valid pick since prices[1] < prices[2] < prices[3]. |
29 |
| -The answer would be sum of their profits which is 2 + 7 + 10 = 19.</pre> |
| 26 | +<b>输入:</b> prices = [10,2,3,4], profits = [100,2,7,10] |
| 27 | +<b>输出:</b> 19 |
| 28 | +<b>解释:</b> 我们不能选择索引为 i=0 的商品,因为不存在索引 j 和 k 满足条件。 |
| 29 | +所以我们能选择的唯一三元组是索引为 1,2 和 3 的商品,这是一个有效的选择,因为 prices[1] < prices[2] < prices[3]。 |
| 30 | +答案就是它们的利润之和,即 2 + 7 + 10 = 19。</pre> |
30 | 31 |
|
31 |
| -<p><strong class="example">Example 2:</strong></p> |
| 32 | +<p><b>示例 2:</b></p> |
32 | 33 |
|
33 | 34 | <pre>
|
34 |
| -<strong>Input:</strong> prices = [1,2,3,4,5], profits = [1,5,3,4,6] |
35 |
| -<strong>Output:</strong> 15 |
36 |
| -<strong>Explanation:</strong> We can select any triplet of items since for each triplet of indices i, j and k such that i < j < k, the condition holds. |
37 |
| -Therefore the maximum profit we can get would be the 3 most profitable items which are indices 1, 3 and 4. |
38 |
| -The answer would be sum of their profits which is 5 + 4 + 6 = 15.</pre> |
| 35 | +<b>输入:</b> prices = [1,2,3,4,5], profits = [1,5,3,4,6] |
| 36 | +<b>输出:</b> 15 |
| 37 | +<b>解释:</b> 我们可以选择任意三件商品,因为对于每个索引三元组 i,j 和 k 满足 i < j < k,条件都成立。 |
| 38 | +因此我们能得到的最大利润就是三件最赚钱的商品,它们的索引分别是 1,3 和 4。 |
| 39 | +答案就是它们的利润之和,即 5 + 4 + 6 = 15。</pre> |
39 | 40 |
|
40 |
| -<p><strong class="example">Example 3:</strong></p> |
| 41 | +<p><b>示例 3:</b></p> |
41 | 42 |
|
42 | 43 | <pre>
|
43 |
| -<strong>Input:</strong> prices = [4,3,2,1], profits = [33,20,19,87] |
44 |
| -<strong>Output:</strong> -1 |
45 |
| -<strong>Explanation:</strong> We can't select any triplet of indices such that the condition holds, so we return -1. |
| 44 | +<b>输入:</b> prices = [4,3,2,1], profits = [33,20,19,87] |
| 45 | +<b>输出:</b> -1 |
| 46 | +<b>解释:</b> 我们不能选择任何满足条件的索引三元组,所以我们返回 -1。 |
46 | 47 | </pre>
|
47 | 48 |
|
48 | 49 | <p> </p>
|
49 |
| -<p><strong>Constraints:</strong></p> |
| 50 | + |
| 51 | +<p><b>提示:</b></p> |
50 | 52 |
|
51 | 53 | <ul>
|
52 | 54 | <li><code>3 <= prices.length == profits.length <= 2000</code></li>
|
|
0 commit comments