結果
問題 | No.972 選び方のスコア |
ユーザー |
![]() |
提出日時 | 2020-05-13 08:20:18 |
言語 | Java (openjdk 23) |
結果 |
WA
|
実行時間 | - |
コード長 | 610 bytes |
コンパイル時間 | 2,287 ms |
コンパイル使用メモリ | 74,232 KB |
実行使用メモリ | 58,904 KB |
最終ジャッジ日時 | 2024-09-14 15:25:21 |
合計ジャッジ時間 | 27,528 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 23 WA * 9 |
ソースコード
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]; for (int i = 0; i < n; i++) { arr[i] = sc.nextInt(); } Arrays.sort(arr); long[] sums = new long[n]; sums[0] = arr[0]; for (int i = 1; i < n; i++) { sums[i] = sums[i - 1] + arr[i]; } long max = Long.MIN_VALUE; for (int i = 1; i <= (n - 1) / 2; i++) { long value = sums[i - 1] + sums[n - 1] - sums[n - i - 1] - (long)arr[i] * i * 2; max = Math.max(max, value); } System.out.println(max); } }