For real-valued x(1), x(2), ... , x(n) with real-valued "responses"y(1), y(2), ... , y(n) and "scores" s(1), s(2), ... ,s(n) we solve the problem ofcomputing the maximum of C(k) = s(1) I {y(1) 3 k(x(1))}+ ... + s(n) I { ... } over allconvex functions k on the line. The article describes a recursive relation and analgorithm based on it to compute this value and an optimal k in O(n(3)) steps. Fora special choice of scores, max C(k) can be interpreted as a generalized (one-sided)Kolmogorov-Smirnov statistic to test for treatment effect in nonparametric analysisof covariance