Problem 3428 · Medium

Maximum and Minimum Sums of at Most Size K Subsequences

Sort the values; each pair of positions (i, j) as min and max contributes a[i] + a[j] times the count of valid middle choices, summed with prefix sums of binomial counts.

Open the interactive visualisation