I just wasted 4 hours of my life this afternoon for a problem.
Basically, I saw the idea of the problem for about 10-15 minutes after reading, but the implementation was hell for me. After quickly wrote the code about 15 minutes later, I sank in a bunch of WAs and lots of debugging codes. I even had to write the checker myself, when bugs kept going until AC after a total of 4 hours.
I saw other people did the problem in just under 1 hour, which I estimate I could do if I (almost) got the code right from first try and didn't fall into that debugging loophole.
This made me questioned, how could I improve my skills at implementation? Can you guys share some tips for me?









Auto comment: topic has been updated by ntk7643 (previous revision, new revision, compare).
If anyone wonder about the problem I mentioned, I can't share the link since it's private. However, I can give a simplified version of the problem here:
Given $$$n$$$ segments $$$[l_1, r_1], [l_2, r_2],..., [l_n, r_n]$$$ and a positive integer $$$d$$$, find $$${a_1, a_2,..., a_n}$$$ such that:
For every $$$1 \le i \le n, l_i \le a_i \le r_i$$$;
$$$max(a_1, a_2,..., a_n) - min(a_1, a_2,..., a_n)$$$ is minimized;
$$$\Sigma_{i=1}^{n} x_i = d$$$.
solve more
solve more
if you're not practicing for OI, use templates for common algorithms and data structures instead of coding them from scratch
For debugging, most of these are obvious but:
-Wall -Wshadow -O2)indexandarray[index]