結果

問題 No.972 選び方のスコア
ユーザー htensaihtensai
提出日時 2020-01-22 08:39:53
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,319 bytes
コンパイル時間 3,835 ms
コンパイル使用メモリ 74,084 KB
実行使用メモリ 66,392 KB
最終ジャッジ日時 2023-09-21 20:21:50
合計ジャッジ時間 30,912 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 916 ms
64,852 KB
testcase_01 AC 880 ms
65,056 KB
testcase_02 AC 861 ms
64,752 KB
testcase_03 AC 654 ms
60,748 KB
testcase_04 AC 876 ms
64,388 KB
testcase_05 AC 855 ms
64,568 KB
testcase_06 AC 890 ms
64,500 KB
testcase_07 AC 743 ms
64,776 KB
testcase_08 AC 776 ms
64,692 KB
testcase_09 AC 769 ms
64,452 KB
testcase_10 AC 771 ms
66,392 KB
testcase_11 AC 814 ms
65,380 KB
testcase_12 AC 834 ms
64,572 KB
testcase_13 AC 822 ms
64,832 KB
testcase_14 AC 816 ms
64,992 KB
testcase_15 AC 778 ms
64,960 KB
testcase_16 AC 837 ms
64,524 KB
testcase_17 AC 812 ms
64,868 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 127 ms
56,032 KB
testcase_26 AC 131 ms
55,788 KB
testcase_27 AC 133 ms
56,012 KB
testcase_28 AC 128 ms
55,784 KB
testcase_29 AC 127 ms
55,772 KB
testcase_30 AC 132 ms
55,816 KB
testcase_31 AC 128 ms
55,756 KB
testcase_32 AC 129 ms
55,732 KB
testcase_33 AC 149 ms
55,744 KB
testcase_34 AC 138 ms
55,900 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[]  args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] arr = new int[n];
        long total = 0;
        for (int i = 0; i < n; i++) {
            arr[i] = sc.nextInt();
            total += arr[i];
        }
        Arrays.sort(arr);
        if (n == 1) {
            System.out.println(0);
            return;
        } else if (n == 2) {
            System.out.println(arr[1] - arr[0]);
            return;
        } else if (n == 3) {
            System.out.println(total - arr[1] * 3L);
            return;
        }
        long max = 0;
        int left = 0;
        int right = n - 1;
        long value = 0;
        while (left < right) {
            value += arr[left] + arr[right];
            long count = (left + 1) * 2;
            max = Math.max(max, value - arr[left + 1] * count);
            left++; 
            right--;
        }
        left = 0;
        right = n - 1;
        value = 0;
        while (left + 1 < right) {
            value += arr[left] + arr[right];
            long count = left + 1;
            max = Math.max(max, value - (arr[left + 1] + arr[left + 2]) * count);
            left++;
            right--;
        }
        System.out.println(max);
    }
}
0