fork download
  1. #include <stdio.h>
  2. #include <limits.h>
  3. #define max(A,B,C) A > (B > C ? B : C) ? A : (B > C ? B : C)
  4. #define N 4
  5.  
  6. int main()
  7. {
  8. int e[N] = {9,8,2,3 };
  9. int i=0;
  10. int j = N-1;
  11. int A = e[i];
  12. int C = e[j];
  13. int B = 0;
  14. int x, AL, CR, BL, BR, m, mp = INT_MAX, L, R;
  15. for(x = i+1 ; x < j; x++) B+=e[x];
  16. m = max(A,B,C);
  17. printf("A=%d B=%d C=%d\n", A, B, C);
  18. while(m < mp)
  19. {
  20. AL = A+e[i+1];
  21. CR = C+e[j-1];
  22. BL = B-e[i+1];
  23. BR = B-e[j-1];
  24. L = max(AL,BL,C);
  25. R = max(A,BR,CR);
  26. if(L<R)
  27. {
  28. A=AL;
  29. B=BL;
  30. i++;
  31. }
  32. else
  33. {
  34. C=CR;
  35. B=BR;
  36. j--;
  37. }
  38. mp = m;
  39. m = max(A,B,C);
  40. printf("A=%d B=%d C=%d MAX=%d\n", A, B, C, m);
  41. }
  42. printf("%d", mp);
  43. return 0;
  44. }
Success #stdin #stdout 0s 2008KB
stdin
Standard input is empty
stdout
A=9 B=10 C=3
A=9 B=8 C=5 MAX=9
A=9 B=0 C=13 MAX=13
9