#include <stdio.h>
#include <limits.h>
#define max(A,B,C) A > (B > C ? B : C) ? A : (B > C ? B : C)
#define N 4
int main()
{
int e[N] = {9,8,2,3 };
int i=0;
int j = N-1;
int A = e[i];
int C = e[j];
int B = 0;
int x, AL, CR, BL, BR, m, mp = INT_MAX, L, R;
for(x = i+1 ; x < j; x++) B+=e[x];
m = max(A,B,C);
printf("A=%d B=%d C=%d\n", A
, B
, C
); while(m < mp)
{
AL = A+e[i+1];
CR = C+e[j-1];
BL = B-e[i+1];
BR = B-e[j-1];
L = max(AL,BL,C);
R = max(A,BR,CR);
if(L<R)
{
A=AL;
B=BL;
i++;
}
else
{
C=CR;
B=BR;
j--;
}
mp = m;
m = max(A,B,C);
printf("A=%d B=%d C=%d MAX=%d\n", A
, B
, C
, m
); }
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxsaW1pdHMuaD4KI2RlZmluZSBtYXgoQSxCLEMpIEEgPiAoQiA+IEMgPyBCIDogQykgPyBBIDogKEIgPiBDID8gQiA6IEMpCiNkZWZpbmUgTiA0CgppbnQgbWFpbigpCnsKCWludCBlW05dID0gezksOCwyLDMgfTsKCWludCBpPTA7CglpbnQgaiA9IE4tMTsKCWludCBBID0gZVtpXTsKCWludCBDID0gZVtqXTsKCWludCBCID0gMDsKCWludCB4LCBBTCwgQ1IsIEJMLCBCUiwgbSwgbXAgPSBJTlRfTUFYLCBMLCBSOwoJZm9yKHggPSBpKzEgOyB4IDwgajsgeCsrKSBCKz1lW3hdOwoJbSA9IG1heChBLEIsQyk7CglwcmludGYoIkE9JWQgQj0lZCBDPSVkXG4iLCBBLCBCLCBDKTsKCXdoaWxlKG0gPCBtcCkKCXsKCQlBTCA9IEErZVtpKzFdOwoJCUNSID0gQytlW2otMV07CgkJQkwgPSBCLWVbaSsxXTsKCQlCUiA9IEItZVtqLTFdOwoJCUwgPSBtYXgoQUwsQkwsQyk7CgkJUiA9IG1heChBLEJSLENSKTsKCQlpZihMPFIpCg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