/* package whatever; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
public int maxSubArray(int[] nums) {
int max_so_far = nums[0];
int curr_max = nums[0];
for (int i = 1; i < nums.length; i++) {
curr_max
= Math.
max(nums
[i
], nums
[i
] + curr_max
); max_so_far
= Math.
max(curr_max, max_so_far
); }
return max_so_far;
}
{
// your code goes here
Ideone x = new Ideone();
int[] arr = {-2, -5, 6, -2, -3, 1, 5, -6};
System.
out.
println(x.
maxSubArray(arr
)); }
}
LyogcGFja2FnZSB3aGF0ZXZlcjsgLy8gZG9uJ3QgcGxhY2UgcGFja2FnZSBuYW1lISAqLwoKaW1wb3J0IGphdmEudXRpbC4qOwppbXBvcnQgamF2YS5sYW5nLio7CmltcG9ydCBqYXZhLmlvLio7CgovKiBOYW1lIG9mIHRoZSBjbGFzcyBoYXMgdG8gYmUgIk1haW4iIG9ubHkgaWYgdGhlIGNsYXNzIGlzIHB1YmxpYy4gKi8KY2xhc3MgSWRlb25lCnsKCSAgcHVibGljIGludCBtYXhTdWJBcnJheShpbnRbXSBudW1zKSB7CgogICAgaW50IG1heF9zb19mYXIgPSBudW1zWzBdOwogICAgaW50IGN1cnJfbWF4ID0gbnVtc1swXTsKCiAgICBmb3IgKGludCBpID0gMTsgaSA8IG51bXMubGVuZ3RoOyBpKyspIHsKICAgICAgY3Vycl9tYXggPSBNYXRoLm1heChudW1zW2ldLCBudW1zW2ldICsgY3Vycl9tYXgpOwogICAgICBtYXhfc29fZmFyID0gTWF0aC5tYXgoY3Vycl9tYXgsIG1heF9zb19mYXIpOwogICAgfQoKICAgIHJldHVybiBtYXhfc29fZmFyOwogIH0KCXB1YmxpYyBzdGF0aWMgdm9pZCBtYWluIChTdHJpbmdbXSBhcmdzKSB0aHJvd3MgamF2YS5sYW5nLkV4Y2VwdGlvbgoJewoJCS8vIHlvdXIgY29kZSBnb2VzIGhlcmUKCQlJZGVvbmUgeCA9IG5ldyBJZGVvbmUoKTsKCQlpbnRbXSBhcnIgPSB7LTIsIC01LCA2LCAtMiwgLTMsIDEsIDUsIC02fTsKCQkKCQlTeXN0ZW0ub3V0LnByaW50bG4oeC5tYXhTdWJBcnJheShhcnIpKTsKCX0KfQ==