Calculate how much profit you make by producing and selling one unit of X, and calculate the same for Y. Also calculate how much profit you make by buying one unit of X from your third-party supplier and selling it, and calculate the same for Y. Since you are going to make a profit on any of these actions, you should try to meet the demand for both X and Y through some combination of these actions, but you have to prioritize based on what makes you the most money. I would suggest writing a function of total profit in terms of p and q, where p is the number of units of X produced, and q is the number of units of Y produced. Then 120 - p should be the number of units of X purchased from the third party supplier and 150 - q should be the number of units of Y purchased from the third party supplier. Then maximize the function.

Constraints are: