Hi I was wondering for the Covaxin vs. Covishield problem, if it would be possible to get an O(1) solution by using maths.
We know that the price of the ith Covaxin or Covishield price can be represented as a+(i-1)b and c+(i-1)d respectively, so taking the partial sum of this series from 1 to k yields that sum of the prices of Covaxin or Covishield are 1/2(2ak + bk^2 - bk) and 1/2(2ck + dk^2 - dk).
Now taking this generalisation we should in theory be able to map these two functions on a cartesian plane to form an ellipse with the sum of their sum of prices being <= X. More formally we can plot 1/2(2ax + bx^2 - bx + 2cy + dy^2 - dy) <= X. From here we just need to develop an O(1) algorithm to maximise the integer pair x, y where x, y lies on or within the above ellipse.
To do this my thinking was that I could simply mathematically maximise point (x, y) on the ellipse, then floor and ceil the values to check the three values (floor(x), floor(y)), (ceil(x), floor(y)), and (floor(x), ceil(y)). However in practice there were too many edge cases I didn’t consider such as negative values, ellipses such that there existed no integer coordinates inside etc.
However in theory would this approach work if all the edge cases were accounted for?
Since all this would require are certain edge cases and a bunch of if cases for the logic.