結果

問題 No.972 選び方のスコア
ユーザー C_nena_EC_nena_E
提出日時 2020-01-18 09:36:20
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,053 ms / 2,000 ms
コード長 1,270 bytes
コンパイル時間 2,356 ms
コンパイル使用メモリ 74,052 KB
実行使用メモリ 67,396 KB
最終ジャッジ日時 2023-09-09 08:13:21
合計ジャッジ時間 29,880 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,053 ms
66,784 KB
testcase_01 AC 955 ms
66,868 KB
testcase_02 AC 940 ms
67,180 KB
testcase_03 AC 691 ms
63,172 KB
testcase_04 AC 958 ms
66,744 KB
testcase_05 AC 929 ms
66,936 KB
testcase_06 AC 987 ms
67,068 KB
testcase_07 AC 825 ms
67,152 KB
testcase_08 AC 813 ms
66,284 KB
testcase_09 AC 853 ms
66,692 KB
testcase_10 AC 851 ms
66,652 KB
testcase_11 AC 805 ms
66,908 KB
testcase_12 AC 907 ms
66,496 KB
testcase_13 AC 918 ms
67,044 KB
testcase_14 AC 845 ms
67,396 KB
testcase_15 AC 868 ms
66,656 KB
testcase_16 AC 887 ms
67,008 KB
testcase_17 AC 870 ms
66,872 KB
testcase_18 AC 122 ms
56,028 KB
testcase_19 AC 924 ms
66,668 KB
testcase_20 AC 936 ms
66,828 KB
testcase_21 AC 944 ms
66,868 KB
testcase_22 AC 1,002 ms
67,044 KB
testcase_23 AC 922 ms
67,040 KB
testcase_24 AC 962 ms
67,356 KB
testcase_25 AC 123 ms
55,932 KB
testcase_26 AC 122 ms
55,540 KB
testcase_27 AC 124 ms
56,064 KB
testcase_28 AC 126 ms
56,472 KB
testcase_29 AC 126 ms
55,768 KB
testcase_30 AC 125 ms
55,716 KB
testcase_31 AC 126 ms
55,752 KB
testcase_32 AC 127 ms
55,744 KB
testcase_33 AC 147 ms
56,036 KB
testcase_34 AC 134 ms
56,264 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] li = new long[n];
        long[] rsw = new long[n+1];
        long ans = 0;
        for(int i = 0; i < n; i++){
            li[i] = sc.nextInt();
        }
        if(n <= 2){
            System.out.println(0);
            return;
        }
        Arrays.sort(li);
        for(int i = 1; i <= n; i++){
            rsw[i] += li[i-1]+rsw[i-1];
        }

        for(int i = 1; i < n-1; i++){
            int left = 1;
            int right = Math.min(i+1,n-i);
            while(Math.abs(right-left) > 1){
                int mid = (left + right) /2;
                if(check(li,i,mid)){
                    left = mid;
                }else{
                    right = mid;
                }
            }
            long val = rsw[i] - rsw[i-left] + rsw[n]-rsw[n-left];
            val -= li[i]*left*2;
            ans = Math.max(ans, val);
        }
        System.out.println(ans);
    }

    static boolean check(long[] li, int i, int mid){
        int n = li.length;
        return (li[n-mid] + li[i-mid])-(2*li[i]) >= 0;
    }
}

0