This is mu function so far:
=max(if(C1:C4<=A1,D1:D4,))
Explanation: look for the maximum value Within the array D1 to D4 if any of the values in C1 to C4 are equal to or less than the value in A1.

Examples:
When C1<=A1 then print D1.
When C2<=A1 then print D2.
When C3<=A1 then print D3.

The problem is when I want to look if two columns are <= A1.
=max(if(C1:C4+F1:F4<=A1,D1:D4+G1:G4,))
It will check if C1+F1<=A1, C2+F2<=A1, C3+F3<=A1, C4+F4<=A1. And print for example D1+G1, D2+G2 etc

I want this formula to check if any of the cells in column C plus any of the cells in column F are <=A1, so for example C1+F3 print D1+G3.

What function do I need to look if any of the values in column C plus any of the values in column F is equal to or less than the value in A1?
And if that is true, how do I print the cells next to the chosen cells?

And how do I add more after that?
Example:C1:C4+F1:F4+I1+I4+L1:L4 if true print D1:D4+G1:G4+J1:J4+M1:M4

Basically this is maximizing columns D+G+J+M when columns C+F+I+L is less than cell A1.

One last thing is that I need this to be a formula, because other formula are connected to these cells and numbers.