i was on this problem for a while 1538G - Подарочный набор , i wrote my code 120665262 / https://codeforces.me/contest/1538/submission/120665262 for solution.
it gives WA on test case 2 where 1103rd numbers do not match.
i used basic geometry to solve the problem.(mayb its called linear programming — i dont know exactly.)
Anyone having suggestions what m doing wrong here. THANKS.
Since the point of intersection may not have integer coordinates you must search the nearby integer coordinates to find the maximum value.See my submission https://codeforces.me/contest/1538/submission/119986616