Question How to solve this ?
| № | Пользователь | Рейтинг |
|---|---|---|
| 1 | jiangly | 3810 |
| 2 | Benq | 3676 |
| 3 | Kevin114514 | 3655 |
| 4 | maroonrk | 3463 |
| 5 | strapple | 3390 |
| 6 | Um_nik | 3387 |
| 7 | tourist | 3384 |
| 8 | heuristica | 3322 |
| 9 | turmax | 3319 |
| 10 | jiangbowen | 3291 |
| Страны | Города | Организации | Всё → |
| № | Пользователь | Вклад |
|---|---|---|
| 1 | Qingyu | 158 |
| 2 | nik_exists | 150 |
| 2 | maspy | 150 |
| 4 | Um_nik | 143 |
| 4 | AmShZ | 143 |
| 6 | Errichto | 139 |
| 7 | adamant | 137 |
| 8 | maroonrk | 134 |
| 9 | BledDest | 132 |
| 10 | qwexd | 129 |
| Название |
|---|



I'm pretty sure coding a greedy is worth a shot. If $$$x = y$$$, the answer is just $$$\frac{nx}{2}$$$; if $$$x \lt y$$$, remove all identical characters you can, then you are left with at most $$$26$$$ different characters, and you just remove those using the $$$y$$$ operation; if $$$x \gt y$$$, store character counts in a heap or a SortedList and always use $$$y$$$ on the max and second max frequency characters. If there is only $$$1$$$ distinct character left, use $$$x$$$ on it.
For the $$$x \gt y$$$ condition, a better method would be to just check if character having the max frequency has the frequency greater than sum of frequency of all the other characters , then the answer would be $$$x*\frac{(2*(max freq) - length of string)}{2} + y*((length of string)-(max freq))$$$ and other wise, it would be possible to cancel out all of the characters with some other character and it would be end up being $$$ \frac{ny}{2} $$$.
That is a good point. It kind of reminds me of this problem.