File tree 3 files changed +37
-1
lines changed
2530.Maximal Score After Applying K Operations
2532.Time to Cross a Bridge
3 files changed +37
-1
lines changed Original file line number Diff line number Diff line change @@ -135,6 +135,24 @@ public:
135
135
};
136
136
```
137
137
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
+
138
156
### ** Go**
139
157
140
158
``` go
Original file line number Diff line number Diff line change @@ -117,6 +117,24 @@ public:
117
117
};
118
118
```
119
119
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
+
120
138
### ** Go**
121
139
122
140
``` go
Original file line number Diff line number Diff line change 94
94
- ` wait_in_left ` :大根堆,存储当前在左岸等待的工人的下标;
95
95
- ` wait_in_right ` :大根堆,存储当前在右岸等待的工人的下标;
96
96
- ` work_in_left ` :小根堆,存储当前在左岸工作的工人放好箱子的时间以及工人的下标;
97
- - ` work_in_right ` :小根堆,存储当前在右岸工作的工人放好箱子的时间以及工人的下标 。
97
+ - ` work_in_right ` :小根堆,存储当前在右岸工作的工人拿好箱子的时间以及工人的下标 。
98
98
99
99
初始时,所有工人都在左岸,因此 ` wait_in_left ` 中存储所有工人的下标。用变量 ` cur ` 记录当前时间。
100
100
You can’t perform that action at this time.
0 commit comments