2218. Maximum Value of K Coins From Piles Hard
1/**
2 * [2218] Maximum Value of K Coins From Piles
3 *
4 * There are n piles of coins on a table. Each pile consists of a positive number of coins of assorted denominations.
5 * In one move, you can choose any coin on top of any pile, remove it, and add it to your wallet.
6 * Given a list piles, where piles[i] is a list of integers denoting the composition of the i^th pile from top to bottom, and a positive integer k, return the maximum total value of coins you can have in your wallet if you choose exactly k coins optimally.
7 *
8 * Example 1:
9 * <img alt="" src="https://assets.leetcode.com/uploads/2019/11/09/e1.png" style="width: 600px; height: 243px;" />
10 * Input: piles = [[1,100,3],[7,8,9]], k = 2
11 * Output: 101
12 * Explanation:
13 * The above diagram shows the different ways we can choose k coins.
14 * The maximum total we can obtain is 101.
15 *
16 * Example 2:
17 *
18 * Input: piles = [[100],[100],[100],[100],[100],[100],[1,1,1,1,1,1,700]], k = 7
19 * Output: 706
20 * Explanation:
21 * The maximum total can be obtained if we choose all coins from the last pile.
22 *
23 *
24 * Constraints:
25 *
26 * n == piles.length
27 * 1 <= n <= 1000
28 * 1 <= piles[i][j] <= 10^5
29 * 1 <= k <= sum(piles[i].length) <= 2000
30 *
31 */
32pub struct Solution {}
33
34// problem: https://leetcode.com/problems/maximum-value-of-k-coins-from-piles/
35// discuss: https://leetcode.com/problems/maximum-value-of-k-coins-from-piles/discuss/?currentPage=1&orderBy=most_votes&query=
36
37// submission codes start here
38
39impl Solution {
40 pub fn max_value_of_coins(piles: Vec<Vec<i32>>, k: i32) -> i32 {
41 0
42 }
43}
44
45// submission codes end
46
47#[cfg(test)]
48mod tests {
49 use super::*;
50
51 #[test]
52 fn test_2218() {
53 }
54}
55
Back
© 2025 bowen.ge All Rights Reserved.