I am reading two analogue inputs (0-1023) and following these on two analogue outputs but would like to cap the two outputs so that the combined total of the two outputs does not exceed 1023.

e.g when both inputs are 1023 then both outputs would be 512.

if input 1 is 0 and input 2 is 1023 the output 1 is 0 and output 2 is 1023

Is there a way to do this without having a complex if then routine.