1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| import java.math.BigInteger; import java.util.Scanner;
public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int n = scanner.nextInt(); int[] nums = new int[n]; int oddMax = -1, singMax = -1; for (int i = 0; i < n; i++) { nums[i] = scanner.nextInt(); if (i % 2 == 0) oddMax = Math.max(oddMax, nums[i]); else singMax = Math.max(singMax, nums[i]); } if (oddMax == singMax) singMax += 1; BigInteger ans = new BigInteger("0"); for (int i = 0; i < n; i++) { int temp = i % 2 == 0 ? oddMax - nums[i] : singMax - nums[i]; ans = ans.add(new BigInteger(String.valueOf(temp))); } System.out.println(ans); } }
|