每个数绝对值不超过2^30; n<=1000000 import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; //数据过大:用bufferedReader public class 读入优先之最大区间和 { public static void main(String[] args) { BufferedReader bf=new BufferedReader(new InputStreamReader(System.in)); String str1=null; String str2=null; try { str1=bf.readLine(); str2=bf.readLine();//读取数据 } catch (IOException e) { e.printStackTrace();//输出信息 } String[] arr=str2.split(" "); //注意是long类型哦 long sum=0; long max = Integer.MIN_VALUE; for (int i = 0; i < arr.length; i++) { sum += Integer.parseInt(arr[i]); max = Math.max(max, sum); if (sum < 0) { sum = 0; } } System.out.println(max); } }