2829. Determine the Minimum Sum of a k-avoiding Array Medium

@problem@discussion
#Math#Greedy



1/**
2 * [2829] Determine the Minimum Sum of a k-avoiding Array
3 *
4 * You are given two integers, n and k.
5 * An array of distinct positive integers is called a k-avoiding array if there does not exist any pair of distinct elements that sum to k.
6 * Return the minimum possible sum of a k-avoiding array of length n.
7 *  
8 * <strong class="example">Example 1:
9 * 
10 * Input: n = 5, k = 4
11 * Output: 18
12 * Explanation: Consider the k-avoiding array [1,2,4,5,6], which has a sum of 18.
13 * It can be proven that there is no k-avoiding array with a sum less than 18.
14 * 
15 * <strong class="example">Example 2:
16 * 
17 * Input: n = 2, k = 6
18 * Output: 3
19 * Explanation: We can construct the array [1,2], which has a sum of 3.
20 * It can be proven that there is no k-avoiding array with a sum less than 3.
21 * 
22 *  
23 * Constraints:
24 * 
25 * 	1 <= n, k <= 50
26 * 
27 */
28pub struct Solution {}
29
30// problem: https://leetcode.com/problems/determine-the-minimum-sum-of-a-k-avoiding-array/
31// discuss: https://leetcode.com/problems/determine-the-minimum-sum-of-a-k-avoiding-array/discuss/?currentPage=1&orderBy=most_votes&query=
32
33// submission codes start here
34
35impl Solution {
36    pub fn minimum_sum(n: i32, k: i32) -> i32 {
37        0
38    }
39}
40
41// submission codes end
42
43#[cfg(test)]
44mod tests {
45    use super::*;
46
47    #[test]
48    fn test_2829() {
49    }
50}
51


Back
© 2025 bowen.ge All Rights Reserved.