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)


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