結果

問題 No.1374 Absolute Game
ユーザー tentententen
提出日時 2021-10-20 13:01:18
言語 Java21
(openjdk 21)
結果
RE  
実行時間 -
コード長 2,028 bytes
コンパイル時間 2,661 ms
コンパイル使用メモリ 77,656 KB
実行使用メモリ 62,120 KB
最終ジャッジ日時 2023-10-20 10:59:04
合計ジャッジ時間 10,121 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 54 ms
53,684 KB
testcase_01 AC 53 ms
53,692 KB
testcase_02 RE -
testcase_03 RE -
testcase_04 AC 53 ms
53,688 KB
testcase_05 AC 52 ms
53,688 KB
testcase_06 AC 55 ms
53,688 KB
testcase_07 AC 53 ms
53,688 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        long even = 0;
        long odd = 0;
        long[] sum = new long[n];
        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = sc.nextInt();
        }
        Arrays.sort(arr);
        for (int i = 0; i < n; i++) {
            int x = arr[i];
            if (i % 2 == 0) {
                even += x;
            } else {
                odd += x;
            }
            if (i > 0) {
                sum[i] = sum[i - 1] + x;
            } else {
                sum[i] = x;
            }
        }
        long ans = Long.MIN_VALUE;
        ans = Math.max(ans, Math.abs(even) - Math.abs(odd));
        if (n % 2 == 0) {
            ans = Math.max(ans, Math.abs(odd) - Math.abs(even));
        }
        int idx = (n - 1) / 2;
        ans = Math.max(ans, Math.abs(sum[idx]) - Math.abs(sum[n - 1] - sum[idx]));
        idx = n / 2 - 1;
        ans = Math.max(ans, Math.abs(sum[n - 1] - sum[idx]) - Math.abs(sum[idx]));
        System.out.println(ans);
    }

    static int getRate(int p, int r) {
        return p / 100 * (100 - r);
    }
    
    static int getMinus(int p, int m) {
        return Math.max(0, p - m);
    }
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public String nextLine() throws Exception {
        return br.readLine();
    }
    
    public String next() throws Exception {
        if (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
}
0