結果
| 問題 |
No.972 選び方のスコア
|
| コンテスト | |
| ユーザー |
htensai
|
| 提出日時 | 2020-01-22 08:39:53 |
| 言語 | Java (openjdk 23) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,319 bytes |
| コンパイル時間 | 2,620 ms |
| コンパイル使用メモリ | 77,688 KB |
| 実行使用メモリ | 69,436 KB |
| 最終ジャッジ日時 | 2024-07-07 13:52:56 |
| 合計ジャッジ時間 | 26,487 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 25 WA * 7 |
ソースコード
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);
}
}
htensai