commit 1197f072a64c080f70d6ad2321cee06d83938de2
parent 39455d512cb5a106281ff50b767e200a9fa02937
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date: Mon, 26 Jun 2023 14:26:27 +0200
Daily Problem
Diffstat:
2 files changed, 24 insertions(+), 1 deletion(-)
diff --git a/Problems/2462.cpp b/Problems/2462.cpp
@@ -0,0 +1,22 @@
+class Solution {
+public:
+ long long totalCost(vector<int> &costs, int k, int candidates) {
+ priority_queue<int, vector<int>, greater<int>> pq1, pq2;
+ int i = 0, j = costs.size() - 1;
+ long long res = 0;
+ while (k--) {
+ while (pq1.size() < candidates && i <= j) pq1.push(costs[i++]);
+ while (pq2.size() < candidates && j >= i) pq2.push(costs[j--]);
+ int a = pq1.size() > 0 ? pq1.top() : INT_MAX;
+ int b = pq2.size() > 0 ? pq2.top() : INT_MAX;
+ if (a <= b) {
+ res += a;
+ pq1.pop();
+ } else {
+ res += b;
+ pq2.pop();
+ }
+ }
+ return res;
+ }
+};
diff --git a/README.md b/README.md
@@ -566,8 +566,9 @@ for solving problems.
| 2421 | Medium | [Number of Good Paths](Problems/2421.cpp) |
| 2439 | Medium | [Minimize Maximum of Array](Problems/2439.cpp) |
| 2444 | Hard | [Count Subarrays With Fixed Bounds](Problems/2444.cpp) |
-| 2448 | Hard | [Minimum Cost to Make Array Equal](Problems/2448.cpp) |
+| 2448 | Hard | [Minimum Cost to Make Array Equal](Problems/2448.cpp) |
| 2461 | Medium | [Maximum Sum of Distinct Subarrays With Length K](Problems/2461.cpp) |
+| 2462 | Medium | [Total Cost to Hire K Workers](Problems/2462.cpp) |
| 2465 | Easy | [Number of Distinct Averages](Problems/2465.cpp) |
| 2466 | Medium | [Count Ways To Build Good Strings](Problems/2466.cpp) |
| 2467 | Medium | [Most Profitable Path in a Tree](Problems/2467.cpp) |