2212.cpp (802B)
1 class Solution { 2 public: 3 vector<int> maximumBobPoints(const int numArrows, const vector<int> &aliceArrows) const { 4 vector<int> res; 5 int maxi = 0; 6 7 for (int i = 0; i < (1 << 11); i++) { 8 unsigned mask = i, score = 0, total = 0; 9 static int crnt[12]; 10 11 memset(crnt, 0x00, sizeof(crnt)); 12 while (mask) { 13 int idx = std::countr_zero(mask); 14 mask ^= 1u << idx++; 15 16 total += crnt[idx] = aliceArrows[idx] + 1; 17 score += idx; 18 } 19 20 if (total <= numArrows && score > maxi) { 21 res = vector<int>(crnt, crnt + 12); 22 res[0] += numArrows - total; 23 maxi = score; 24 } 25 } 26 27 return res; 28 } 29 };