Skip to content

Commit 5446391

Browse files
authored
update: 添加问题“3075.幸福值最大化的选择方案”的代码和题解+ newSolution.title.extra test (#1280)
* archive: Time!!! * word: en * 3075: WA.cpp (#1279) * 3075: AC.cpp+py + CE.go (#1279) cpp - AC,86.52%,92.70% cpp - AC,Cut,86.52%,96.07% py - AC,39.26%,97.55% * 3075: AC.go+rust + CE.java (#1279) go - AC,38.46%,30.77% rust - AC,33.33%,55.56% java - 光想着long好像可以直接+int了 * 3075: CE.java (#1279) 哦哦 刚刚是RE * 3075: AC.java (#1279) java - AC,60.64%,40.43% * update: 添加问题“3075.幸福值最大化的选择方案”的代码和题解+ newSolution.title.extra test (#1280) Signed-off-by: LetMeFly666 <[email protected]> * article: 新文框架 * 1 * update: 添加问题“3075.幸福值最大化的选择方案”的代码和题解+ newSolution.title.extra test (删了又回) 换行测试 (#1281) Signed-off-by: LetMeFly666 <[email protected]> * update: 添加问题“3075.幸福值最大化的选择方案”的代码和题解+ newSolution.title.extra test (删了又回) 换行测试 (#1284) Signed-off-by: LetMeFly666 <[email protected]> * docs: rm duplicated readme * fix: error address --------- Signed-off-by: LetMeFly666 <[email protected]>
1 parent dedb92e commit 5446391

21 files changed

+673
-83
lines changed

.commitTitleExtra

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
+ newSolution.title.extra test
2+
(删了又回)
3+
换行测试

.commitmsg

Lines changed: 0 additions & 6 deletions
This file was deleted.

.vscode/settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"*.wxss": "css",
55
"*.wxml": "html",
66
".commitmsg": "git-commit",
7+
".commitTitleExtra": "git-commit",
78
"array": "cpp",
89
"atomic": "cpp",
910
"*.tcc": "cpp",
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2025-12-25 12:56:03
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2025-12-25 12:59:03
6+
*/
7+
#if defined(_WIN32) || defined(__APPLE__)
8+
#include "_[1,2]toVector.h"
9+
#endif
10+
11+
typedef long long ll;
12+
class Solution {
13+
public:
14+
ll maximumHappinessSum(vector<int>& happiness, int k) {
15+
sort(happiness.begin(), happiness.end(), greater<>());
16+
ll ans = 0;
17+
for (int i = 0; i < k; i++) {
18+
ans += max(0, happiness[i] - i);
19+
}
20+
return ans;
21+
}
22+
};
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2025-12-25 12:56:03
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2025-12-25 13:08:10
6+
*/
7+
package main
8+
9+
import "sort"
10+
11+
func maximumHappinessSum(happiness []int, k int) (ans int64) {
12+
sort.Slice(happiness, func(i, j int) bool { return happiness[i] > happiness[j] })
13+
for i := 0; i < k; i++ {
14+
happiness[i] -= i
15+
if happiness[i] <= 0 {
16+
return
17+
}
18+
ans += int64(happiness[i])
19+
}
20+
return
21+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2025-12-25 12:56:03
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2025-12-25 13:18:34
6+
*/
7+
import java.util.Arrays;
8+
9+
class Solution {
10+
public long maximumHappinessSum(int[] happiness, int k) {
11+
Arrays.sort(happiness);
12+
long ans = 0;
13+
int n = happiness.length;
14+
for (int i = 0; i < k; i++) {
15+
if (happiness[n - i - 1] <= i) {
16+
return ans;
17+
}
18+
ans += happiness[n - i - 1] - i;
19+
}
20+
return ans;
21+
}
22+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
'''
2+
Author: LetMeFly
3+
Date: 2025-12-25 12:56:03
4+
LastEditors: LetMeFly.xyz
5+
LastEditTime: 2025-12-25 13:02:05
6+
'''
7+
from typing import List
8+
9+
class Solution:
10+
def maximumHappinessSum(self, happiness: List[int], k: int) -> int:
11+
return sum(max(0, h - i) for i, h in enumerate(sorted(happiness, reverse=True)[:k]))
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2025-12-25 12:56:03
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2025-12-25 13:12:12
6+
*/
7+
impl Solution {
8+
pub fn maximum_happiness_sum(mut happiness: Vec<i32>, k: i32) -> i64 {
9+
let mut ans: i64 = 0;
10+
happiness.sort_by(|a: &i32, b: &i32| b.cmp(a));
11+
for i in 0..k {
12+
if happiness[i as usize] <= i {
13+
return ans;
14+
}
15+
ans += (happiness[i as usize] - i) as i64;
16+
}
17+
ans
18+
}
19+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2025-12-25 12:59:03
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2025-12-25 13:00:12
6+
*/
7+
#if defined(_WIN32) || defined(__APPLE__)
8+
#include "_[1,2]toVector.h"
9+
#endif
10+
11+
typedef long long ll;
12+
class Solution {
13+
public:
14+
ll maximumHappinessSum(vector<int>& happiness, int k) {
15+
sort(happiness.begin(), happiness.end(), greater<>());
16+
ll ans = 0;
17+
for (int i = 0; i < k; i++) {
18+
happiness[i] -= i;
19+
if (happiness[i] <= 0) {
20+
return ans;
21+
}
22+
ans += happiness[i];
23+
}
24+
return ans;
25+
}
26+
};

Codes/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
* @LastEditTime: 2025-11-01 22:18:35
66
*/
77
pub struct Solution;
8-
include!("3074-apple-redistribution-into-boxes.rs"); // 这个fileName是会被脚本替换掉的
8+
include!("3075-maximize-happiness-of-selected-children.rs"); // 这个fileName是会被脚本替换掉的

0 commit comments

Comments
 (0)