leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

1752.cpp (662B)


0 1 // Simulation 2 class Solution { 3 public: 4 int maximumScore(int a, int b, int c) { 5 priority_queue<int> pq; 6 pq.push(a), pq.push(b), pq.push(c); 7 8 int res = 0; 9 while (pq.size() >= 2) { 10 int a = pq.top(); 11 pq.pop(); 12 int b = pq.top(); 13 pq.pop(); 14 if (a > 1) pq.push(a - 1); 15 if (b > 1) pq.push(b - 1); 16 res++; 17 } 18 return res; 19 } 20 }; 21 22 // Math 23 class Solution { 24 public: 25 int maximumScore(const int a, const int b, const int c) const { 26 const int total = a + b + c; 27 return min(total / 2, total - max({a, b, c})); 28 } 29 };