- Given
4, 2
and 6
output 4, 2
no capping needed (ncn), keep order (ko)
- Given
2, 4
and 6
output 2, 4
ncn, ko
- Given
3, 3
and 6
output 3, 3
ncn
- Given
3, 3
and 7
output 3, 3
ncn
- Given
4, 4, 2
and 5
output 2, 2, 1
cth, koor any permutation (oap)
- Given
2, 4, 4
and 5
output 1, 2, 2
cth, kooap
- Given
4, 4, 2
and 4
output 1, 2, 1
or 2, 1, 1
cth, cath, kooap
- Given
2, 4, 4
and 4
output 1, 1, 2
or 1, 2, 1
cth, cath, kooap
- Both input and output are all about positive integers (>0)
- The number of values in the input and output list are equal.
- The sum of the output values is exactly equal to
m
or less than m
only if the sum of the input values was already lower.
- If the sum of the values in the input list is already lower then or equal to
m
, no capping is needed. (ncn)
- Cap the highest values first (cth)
- When multiple values are the highest value and equally high, it doesn't matter which you cap. (cath)
- The capped values in the output list have to be in the same order as their original values in the input list. (ko)
- When at some point (thinking iteratively) all values are equally high, it stops being important which you cap.
- If there's no solution output an error or a falsy value.
The shortest valid answer - measured in bytes - wins.
Apart form the rules, I'm interested to see a program that keeps a value intact as long as possible. Consider the input values a plant each with the heights 10,2,10
and the maximum m
=5, it would be a waste to cap the baby plant in the middle.