Assume a firm both sells its product and purchases its resources in imperfectly competitive markets. Under the above assumption, state the criterion (necessary and sufficient condition) for a firm to employ its resources in such a manner as to produce an optimal output which maximizes its profits.