class Solution
{
public:
string longestDiverseString(int a, int b, int c)
{
priority_queue<pair<int, char>, vector<pair<int, char>>> pq;
string res = "";
if (a > 0)
{
pq.push({a, 'a'});
}
if (b > 0)
{
pq.push({b, 'b'});
}
if (c > 0)
{
pq.push({c, 'c'});
}
while (pq.size() > 1)
{
int c1 = pq.top().first;
char ch1 = pq.top().second;
pq.pop();
if (c1 >= 2)
{
res += ch1;
res += ch1;
c1 -= 2;
}
else
{
res += ch1;
c1--;
}
int c2 = pq.top().first;
char ch2 = pq.top().second;
pq.pop();
if (c2 >= 2 && c2 >= c1)
{
res += ch2;
res += ch2;
c2 -= 2;
}
else
{
res += ch2;
c2--;
}
if (c1 > 0)
{
pq.push({c1, ch1});
}
if (c2 > 0)
{
pq.push({c2, ch2});
}
}
if (!pq.empty())
{
char ch = res[res.length() - 1];
if (pq.top().second != ch)
{
if (pq.top().first >= 2)
{
res += pq.top().second;
res += pq.top().second;
}
else
{
res += pq.top().second;
}
}
}
return res;
}
};