Question How to solve this ?
# | User | Rating |
---|---|---|
1 | tourist | 4009 |
2 | jiangly | 3904 |
3 | Radewoosh | 3646 |
4 | jqdai0815 | 3620 |
4 | Benq | 3620 |
6 | orzdevinwang | 3529 |
7 | ecnerwala | 3494 |
8 | Um_nik | 3396 |
9 | gamegame | 3386 |
10 | maroonrk | 3350 |
# | User | Contrib. |
---|---|---|
1 | cry | 164 |
1 | maomao90 | 164 |
3 | Um_nik | 163 |
4 | atcoder_official | 160 |
5 | -is-this-fft- | 158 |
6 | awoo | 157 |
6 | adamant | 157 |
8 | nor | 154 |
9 | TheScrasse | 153 |
10 | Dominater069 | 152 |
Name |
---|
I'm pretty sure coding a greedy is worth a shot. If $$$x = y$$$, the answer is just $$$\frac{nx}{2}$$$; if $$$x < 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 > 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>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.