fork(3) download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. func(6, 7, 8, 9, 4, 5);
  13. func(9, 12, 4, 7, 10, 2, 5, 8, 11, 3);
  14. func(6, 8, 3, 5, 7, 2, 4, 6);
  15. func(4, 3, 2, 9, 8);
  16. func(100, 10, 120, 90);
  17. }
  18.  
  19. static void func(int... arr)
  20. {
  21. int sum = 0;
  22. for (int i: arr)
  23. sum += i;
  24. int a = 0;
  25. int left = 0, mid = 0;
  26. int best = 0;
  27. for (int b = 0; b < arr.length; b++)
  28. {
  29. mid += arr[b];
  30. while (a < b && Math.min(left + arr[a], mid - arr[a]) > Math.min(left, mid))
  31. {
  32. left += arr[a];
  33. mid -= arr[a];
  34. a++;
  35. }
  36. int right = sum - mid - left;
  37. best = Math.max(best,
  38. mid + left + right - Math.max(mid, Math.max(left, right)));
  39. }
  40. System.out.println(best);
  41. }
  42. }
Success #stdin #stdout 0.04s 4386816KB
stdin
Standard input is empty
stdout
22
46
26
17
200