太菜了,只A了第一题和第二题,第三题卡5%😥
public class Test15 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); for (int q = 0; q < t; q++){ int n = sc.nextInt(); int[] nums = new int[n]; for (int i = 0; i < n; i++) nums[i] = sc.nextInt(); Arrays.sort(nums); // 找分界点 // 打表 int[] table = new int[n]; int temp = 0; for (int j = 0; j < n; j++){ temp = temp + nums[j]; table[j] = temp; } int half = 0; int j = 0; for (j = n - 1; j > 0; j--){ half = half + nums[j]; if(half > table[j - 1]) break; } half = half - nums[j]; System.out.println(table[n - 1] - 2 * half); } } }
全部评论
(0) 回帖