五月天青色头像情侣网名,国产亚洲av片在线观看18女人,黑人巨茎大战俄罗斯美女,扒下她的小内裤打屁股

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

LeetCode 2830. Maximize the Profit as the Salesman

2023-08-21 10:28 作者:您是打尖兒還是住店呢  | 我要投稿

You are given an integer?n?representing the number of houses on a number line, numbered from?0?to?n - 1.

Additionally, you are given a 2D integer array?offers?where?offers[i] = [starti, endi, goldi], indicating that?ith?buyer wants to buy all the houses from?starti?to?endi?for?goldi?amount of gold.

As a salesman, your goal is to?maximize?your earnings by strategically selecting and selling houses to buyers.

Return?the maximum amount of gold you can earn.

Note?that different buyers can't buy the same house, and some houses may remain unsold.

?

Example 1:

Input: n = 5, offers = [[0,0,1],[0,2,2],[1,3,2]]

Output: 3

Explanation: There are 5 houses numbered from 0 to 4 and there are 3 purchase offers. We sell houses in the range [0,0] to 1st buyer for 1 gold and houses in the range [1,3] to 3rd buyer for 2 golds. It can be proven that 3 is the maximum amount of gold we can achieve.

Example 2:

Input: n = 5, offers = [[0,0,1],[0,2,10],[1,3,2]]

Output: 10

Explanation: There are 5 houses numbered from 0 to 4 and there are 3 purchase offers. We sell houses in the range [0,2] to 2nd buyer for 10 golds. It can be proven that 10 is the maximum amount of gold we can achieve.

?

Constraints:

  • 1 <= n <= 105

  • 1 <= offers.length <= 105

  • offers[i].length == 3

  • 0 <= starti?<= endi?<= n - 1

  • 1 <= goldi?<= 103

----------------------------

給你一個整數(shù)?n?表示數(shù)軸上的房屋數(shù)量,編號從?0?到?n - 1?。

另給你一個二維整數(shù)數(shù)組?offers?,其中?offers[i] = [starti, endi, goldi]?表示第?i?個買家想要以?goldi?枚金幣的價格購買從?starti?到?endi?的所有房屋。

作為一名銷售,你需要有策略地選擇并銷售房屋使自己的收入最大化。

返回你可以賺取的金幣的最大數(shù)目。

注意?同一所房屋不能賣給不同的買家,并且允許保留一些房屋不進行出售。

?

示例 1:

輸入:n = 5, offers = [[0,0,1],[0,2,2],[1,3,2]]輸出:3解釋:有 5 所房屋,編號從 0 到 4 ,共有 3 個購買要約。 將位于 [0,0] 范圍內(nèi)的房屋以 1 金幣的價格出售給第 1 位買家,并將位于 [1,3] 范圍內(nèi)的房屋以 2 金幣的價格出售給第 3 位買家。 可以證明我們最多只能獲得 3 枚金幣。

示例 2:

輸入:n = 5, offers = [[0,0,1],[0,2,10],[1,3,2]]輸出:10解釋:有 5 所房屋,編號從 0 到 4 ,共有 3 個購買要約。 將位于 [0,2] 范圍內(nèi)的房屋以 10 金幣的價格出售給第 2 位買家。 可以證明我們最多只能獲得 10 枚金幣。

?

---------------------

參照了lee215的代碼,代碼根據(jù)題目稍微調(diào)整了一下,就出來了,真的不容易??;

下面是代碼:


Runtime:?86 ms, faster than?100.00%?of?Java?online submissions for?Maximize the Profit as the Salesman.

Memory Usage:?110.5 MB, less than?75.00%?of?Java?online submissions for?Maximize the Profit as the Salesman.


LeetCode 2830. Maximize the Profit as the Salesman的評論 (共 條)

分享到微博請遵守國家法律
丰镇市| 纳雍县| 元江| 临湘市| 中西区| 通榆县| 格尔木市| 林周县| 津市市| 柘荣县| 贵阳市| 景德镇市| 乌拉特中旗| 郸城县| 前郭尔| 科技| 常德市| 和平县| 子洲县| 吕梁市| 南宁市| 西盟| 老河口市| 株洲市| 南宁市| 嫩江县| 临夏县| 昌江| 迁安市| 独山县| 察哈| 抚顺市| 新化县| 郁南县| 喀喇沁旗| 盖州市| 盐亭县| 沧州市| 洱源县| 南开区| 安新县|