2830. Maximize the Profit as the Salesman Medium
1/**
2 * [2830] Maximize the Profit as the Salesman
3 *
4 * You are given an integer n representing the number of houses on a number line, numbered from 0 to n - 1.
5 * Additionally, you are given a 2D integer array offers where offers[i] = [starti, endi, goldi], indicating that i^th buyer wants to buy all the houses from starti to endi for goldi amount of gold.
6 * As a salesman, your goal is to maximize your earnings by strategically selecting and selling houses to buyers.
7 * Return the maximum amount of gold you can earn.
8 * Note that different buyers can't buy the same house, and some houses may remain unsold.
9 *
10 * <strong class="example">Example 1:
11 *
12 * Input: n = 5, offers = [[0,0,1],[0,2,2],[1,3,2]]
13 * Output: 3
14 * Explanation: There are 5 houses numbered from 0 to 4 and there are 3 purchase offers.
15 * We sell houses in the range [0,0] to 1^st buyer for 1 gold and houses in the range [1,3] to 3^rd buyer for 2 golds.
16 * It can be proven that 3 is the maximum amount of gold we can achieve.
17 *
18 * <strong class="example">Example 2:
19 *
20 * Input: n = 5, offers = [[0,0,1],[0,2,10],[1,3,2]]
21 * Output: 10
22 * Explanation: There are 5 houses numbered from 0 to 4 and there are 3 purchase offers.
23 * We sell houses in the range [0,2] to 2^nd buyer for 10 golds.
24 * It can be proven that 10 is the maximum amount of gold we can achieve.
25 *
26 *
27 * Constraints:
28 *
29 * 1 <= n <= 10^5
30 * 1 <= offers.length <= 10^5
31 * offers[i].length == 3
32 * 0 <= starti <= endi <= n - 1
33 * 1 <= goldi <= 10^3
34 *
35 */
36pub struct Solution {}
37
38// problem: https://leetcode.com/problems/maximize-the-profit-as-the-salesman/
39// discuss: https://leetcode.com/problems/maximize-the-profit-as-the-salesman/discuss/?currentPage=1&orderBy=most_votes&query=
40
41// submission codes start here
42
43impl Solution {
44 pub fn maximize_the_profit(n: i32, offers: Vec<Vec<i32>>) -> i32 {
45 0
46 }
47}
48
49// submission codes end
50
51#[cfg(test)]
52mod tests {
53 use super::*;
54
55 #[test]
56 fn test_2830() {
57 }
58}
59
Back
© 2025 bowen.ge All Rights Reserved.