結果

問題 No.972 選び方のスコア
ユーザー tentententen
提出日時 2022-08-30 10:44:07
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,321 bytes
コンパイル時間 2,176 ms
コンパイル使用メモリ 77,928 KB
実行使用メモリ 51,880 KB
最終ジャッジ日時 2024-04-24 20:51:00
合計ジャッジ時間 12,782 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 322 ms
51,880 KB
testcase_01 AC 322 ms
51,836 KB
testcase_02 AC 312 ms
51,704 KB
testcase_03 AC 208 ms
47,412 KB
testcase_04 AC 338 ms
51,020 KB
testcase_05 AC 314 ms
51,464 KB
testcase_06 AC 315 ms
51,780 KB
testcase_07 AC 285 ms
48,736 KB
testcase_08 AC 254 ms
50,956 KB
testcase_09 AC 255 ms
48,628 KB
testcase_10 AC 244 ms
51,068 KB
testcase_11 AC 253 ms
51,372 KB
testcase_12 AC 258 ms
51,204 KB
testcase_13 AC 256 ms
50,864 KB
testcase_14 AC 249 ms
51,088 KB
testcase_15 AC 306 ms
51,000 KB
testcase_16 AC 299 ms
51,152 KB
testcase_17 AC 298 ms
51,228 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 47 ms
36,808 KB
testcase_26 AC 45 ms
36,764 KB
testcase_27 AC 45 ms
37,360 KB
testcase_28 AC 46 ms
36,808 KB
testcase_29 AC 45 ms
36,784 KB
testcase_30 AC 44 ms
37,040 KB
testcase_31 AC 45 ms
37,240 KB
testcase_32 AC 46 ms
37,172 KB
testcase_33 AC 47 ms
37,364 KB
testcase_34 AC 46 ms
37,480 KB
権限があれば一括ダウンロードができます

ソースコード

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[] values = new long[n];
        for (int i = 0; i < n; i++) {
            values[i] = sc.nextInt();
        }
        Arrays.sort(values);
        long sum = 0;
        long ans = 0;
        for (int i = 1; i < n - i; i++) {
            sum += values[i - 1] + values[n - i];
            ans = Math.max(ans, sum - i * 2 * values[i]);
        }
        System.out.println(ans);
    }
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    StringBuilder sb = new StringBuilder();
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public double nextDouble() throws Exception {
        return Double.parseDouble(next());
    }
    
    public String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
    
}
0