Comments

Thank you really much!

By the way, is there any tips that can help me in writing the code that works/less buggy on my first try (to reduce time for painful debugging)?

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$$$.

Auto comment: topic has been updated by ntk7643 (previous revision, new revision, compare).