Good morning/afternoon/evening/night dear codeforces community!
I have been learning Go language to start developing in Back-end, so I decided to practice it by solving simple problems from codeforces. However, I am facing a problem in this problem. Initially I implemented sorting by my own comparator to sort the paired(implemented via struct) array. However I got TLE. After that, I implemented merge sort by my own, and even after this I got TLE again. I thought that problem was in binary seacrh(maybe I write something wrong), so I replaced it with two-pointers method. Unfortunately I got TLE again. Can you tell me, is it possible to get "Accepted" in this problem using Golang?
The final version of code is right here -> https://codeforces.net/problemset/submission/580/226466440
Thanks for your consideration.
As in many languages the easiest way to do IO isn't the fastest.
226471399 is your first version with the input done using bufio.scanner (140ms). There are further optimizations possible involving scanner.Bytes() instead of scanner.Text().
Very BIG thanks. You helped me a lot.
Your method allows to input data only separated by a line. I want to read an array in one line, is there a solution for it?
Idk if my submissions can help, but I was using go for quite some time. Look for any of my submissions in Go, there will be fast IO functions.
Thanks, it works now <3
Actually it's recommended to use C/C++ to do competitive programming, for other languages are not made for pure efficiency. In my opinion, in your situation it's not a very good idea to practice simple problems on CF. Use a training site instead. However, if you really want to stick to CF, use a macro template so you don't have to do those tricky optimization every time.
Yeah I know. As I said before, I am only learning it, and I am solving problems to get used to its syntax.
Well I've used Go a lot and haven't had many issues related to performance. If you have good knowledge of how the language works, you can easily use it. Plus it's incredibly fun.