Let (x 1, y 1),…, (x n, y n) be a sample of points in , consisting of two subsamples (x 1, y 1),…, (x n1, y n1) and (x n1+1, y n1+1),…, (x n, y n), where n = n 1 + n 2. We consider the problem of separating the two subsamples by a convex contrast curve k…that is, a real-valued convex function x → k(x). For given curve k we consider the relative frequency p 1 of points of the first sample above the graph of k similarly p 2. The goal is to choose k such that the difference in relative frequency p 1 – p 2 becomes maximal. This maximal value can be regarded as a generalized one-sided Kolmogorov-Smirnov test statistic , where p 1(A) = (1/n 1)#{i ≤ n 1 : (xi, y i) ∈ A}, p 2(A) = (1/n 2#{n 1 + 1 ≤ i ≤ n : (x i, y i) ∈ A} and is the class of all epigraphs {(x y) : k(x) ≤ y} of convex functions k. The standard Kolmogorov-Smirnov test statistic corresponds to the class consisting of all sets —that is, epigraphs of constant functions. Test statistics of this form arise in nonparametric analysis of covariance where the regression function is assumed to be convex. In this article we give a recursive relation and an algorithm based on it to compute the value KS and an optimal convex contrast curve in O(n 3) steps. The convexity assumptions on the sets of and on the nonparametric regression function are interrelated; this is explained in the large sample situation where n 1 Λ n 2 → + ∞.