Problem link: https://acm.timus.ru/problem.aspx?space=1&num=1522
In this problem all you have to do is to come up with clever sorting comparator.
This one is fine:
~~~~~ int sign(int x) { return x < 0 ? -1 : x > 0; } struct info_t { int a, b, c, id; int get() const { if (a <= c) { return (a + b); } else { return -(b + c); } } bool operator <(const info_t &y) const { int xg = this->get(), yg = y.get(); if (sgn(xg) != sgn(yg)) { return sgn(xg) > sgn(yg); } else { return xg < yg; } } }; ~~~~~