commit 7afe9d85ae8503e3a6ff01329325693512cd15f0
parent 0139196197967243a515de3c3eb7eb89d8dd09d1
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date: Tue, 25 Jun 2024 13:34:57 +0200
1 Random Problem
Diffstat:
2 files changed, 30 insertions(+), 0 deletions(-)
diff --git a/Problems/2212.cpp b/Problems/2212.cpp
@@ -0,0 +1,29 @@
+class Solution {
+ public:
+ vector<int> maximumBobPoints(const int numArrows, const vector<int> &aliceArrows) const {
+ vector<int> res;
+ int maxi = 0;
+
+ for (int i = 0; i < (1 << 11); i++) {
+ unsigned mask = i, score = 0, total = 0;
+ static int crnt[12];
+
+ memset(crnt, 0x00, sizeof(crnt));
+ while (mask) {
+ int idx = std::countr_zero(mask);
+ mask ^= 1u << idx++;
+
+ total += crnt[idx] = aliceArrows[idx] + 1;
+ score += idx;
+ }
+
+ if (total <= numArrows && score > maxi) {
+ res = vector<int>(crnt, crnt + 12);
+ res[0] += numArrows - total;
+ maxi = score;
+ }
+ }
+
+ return res;
+ }
+};
diff --git a/README.md b/README.md
@@ -1080,6 +1080,7 @@ for solving problems.
| 2192 | Medium | [All Ancestors of a Node in a Directed Acyclic Graph](Problems/2192.cpp) |
| 2196 | Medium | [Create Binary Tree From Descriptions](Problems/2196.cpp) |
| 2201 | Medium | [Count Artifacts That Can Be Extracted](Problems/2201.cpp) |
+| 2212 | Medium | [Maximum Points in an Archery Competition](Problems/2212.cpp) |
| 2215 | Easy | [Find the Difference of Two Arrays](Problems/2215.cpp) |
| 2218 | Hard | [Maximum Value of K Coins From Piles](Problems/2218.cpp) |
| 2221 | Medium | [Find Triangular Sum of an Array](Problems/2221.cpp) |