Untitled

mail@pastecode.io avatar
unknown
plain_text
7 months ago
1.0 kB
0
Indexable
Never
import java.util.Scanner;

public class Main {
    public static int maximumCost(int[] A, int[] B) {
        int N = A.length;
        int maxCost = 0;

        for (int i = 0; i < N / 2; i++) {
            int diffA = Math.abs(A[i] - A[N - i - 1]);
            int diffB = Math.abs(B[i] - B[N - i - 1]);

            if (diffB > diffA) {
                maxCost += diffB;
                A[i] = B[i];
                A[N - i - 1] = B[N - i - 1];
            } else {
                maxCost += diffA;
            }
        }

        return maxCost;
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int[] A = new int[N];
        int[] B = new int[N];

        for (int i = 0; i < N; i++) {
            A[i] = scanner.nextInt();
        }

        for (int i = 0; i < N; i++) {
            B[i] = scanner.nextInt();
        }

        int result = maximumCost(A, B);
        System.out.println(result);
    }
}