Skip to content

Commit 9886834

Browse files
committedJan 8, 2023
feat: add cpp solution to lc problem: No.2530
No.2530.Maximal Score After Applying K Operations
1 parent 45e08b6 commit 9886834

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed
 

‎solution/2500-2599/2530.Maximal Score After Applying K Operations/README.md

+18
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,24 @@ public:
135135
};
136136
```
137137
138+
```cpp
139+
class Solution {
140+
public:
141+
long long maxKelements(vector<int>& nums, int k) {
142+
make_heap(nums.begin(), nums.end());
143+
long long ans = 0;
144+
while (k--) {
145+
int v = nums[0];
146+
ans += v;
147+
pop_heap(nums.begin(), nums.end());
148+
nums.back() = (v + 2) / 3;
149+
push_heap(nums.begin(), nums.end());
150+
}
151+
return ans;
152+
}
153+
};
154+
```
155+
138156
### **Go**
139157

140158
```go

‎solution/2500-2599/2530.Maximal Score After Applying K Operations/README_EN.md

+18
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,24 @@ public:
117117
};
118118
```
119119
120+
```cpp
121+
class Solution {
122+
public:
123+
long long maxKelements(vector<int>& nums, int k) {
124+
make_heap(nums.begin(), nums.end());
125+
long long ans = 0;
126+
while (k--) {
127+
int v = nums[0];
128+
ans += v;
129+
pop_heap(nums.begin(), nums.end());
130+
nums.back() = (v + 2) / 3;
131+
push_heap(nums.begin(), nums.end());
132+
}
133+
return ans;
134+
}
135+
};
136+
```
137+
120138
### **Go**
121139

122140
```go

‎solution/2500-2599/2532.Time to Cross a Bridge/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@
9494
- `wait_in_left`:大根堆,存储当前在左岸等待的工人的下标;
9595
- `wait_in_right`:大根堆,存储当前在右岸等待的工人的下标;
9696
- `work_in_left`:小根堆,存储当前在左岸工作的工人放好箱子的时间以及工人的下标;
97-
- `work_in_right`:小根堆,存储当前在右岸工作的工人放好箱子的时间以及工人的下标
97+
- `work_in_right`:小根堆,存储当前在右岸工作的工人拿好箱子的时间以及工人的下标
9898

9999
初始时,所有工人都在左岸,因此 `wait_in_left` 中存储所有工人的下标。用变量 `cur` 记录当前时间。
100100

0 commit comments

Comments
 (0)
Please sign in to comment.