Do I just have to switch over from java? Full code: https://pastebin.com/5HDQ6kRa
The logic should be correct but it's TLEing for some cases, and I'm pretty sure I have the optimal logic, but it's either cuz Java is slow or something w/ the implementation of the code