3,422
社区成员
发帖
与我相关
我的任务
分享
import java.util.Arrays;
import java.util.Scanner;
// 算法提高 求最大值
public class Main9 {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int c=sc.nextInt();
int b[]=new int[c];
int array[]=new int[b.length*2];
for(int i=0;i<(array.length);i++){
array[i]=sc.nextInt();
}
for(int i=0;i<b.length;i++){
b[i]=array[(i+1)*2-1]+array[(i+1)*2-2];
}
Arrays.sort(b);
for (int i : b) {
System.out.println(i);
}
if(c==1)
if(b[b.length-1]>=0)
System.out.println(b[b.length-1]);
else System.out.println();
else
if(b[b.length-1]>=0&&b[b.length-2]>=0)
System.out.println(b[b.length-1]+b[b.length-2]);
else System.out.println();
}
}