結果
| 問題 |
No.1374 Absolute Game
|
| コンテスト | |
| ユーザー |
tenten
|
| 提出日時 | 2021-10-20 13:01:18 |
| 言語 | Java (openjdk 23) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 2,028 bytes |
| コンパイル時間 | 3,818 ms |
| コンパイル使用メモリ | 77,836 KB |
| 実行使用メモリ | 48,080 KB |
| 最終ジャッジ日時 | 2024-09-20 06:33:08 |
| 合計ジャッジ時間 | 9,601 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 4 WA * 20 RE * 2 |
ソースコード
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 even = 0;
long odd = 0;
long[] sum = new long[n];
int[] arr = new int[n];
for (int i = 0; i < n; i++) {
arr[i] = sc.nextInt();
}
Arrays.sort(arr);
for (int i = 0; i < n; i++) {
int x = arr[i];
if (i % 2 == 0) {
even += x;
} else {
odd += x;
}
if (i > 0) {
sum[i] = sum[i - 1] + x;
} else {
sum[i] = x;
}
}
long ans = Long.MIN_VALUE;
ans = Math.max(ans, Math.abs(even) - Math.abs(odd));
if (n % 2 == 0) {
ans = Math.max(ans, Math.abs(odd) - Math.abs(even));
}
int idx = (n - 1) / 2;
ans = Math.max(ans, Math.abs(sum[idx]) - Math.abs(sum[n - 1] - sum[idx]));
idx = n / 2 - 1;
ans = Math.max(ans, Math.abs(sum[n - 1] - sum[idx]) - Math.abs(sum[idx]));
System.out.println(ans);
}
static int getRate(int p, int r) {
return p / 100 * (100 - r);
}
static int getMinus(int p, int m) {
return Math.max(0, p - m);
}
}
class Scanner {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer("");
public Scanner() throws Exception {
}
public int nextInt() throws Exception {
return Integer.parseInt(next());
}
public long nextLong() throws Exception {
return Long.parseLong(next());
}
public String nextLine() throws Exception {
return br.readLine();
}
public String next() throws Exception {
if (!st.hasMoreTokens()) {
st = new StringTokenizer(br.readLine());
}
return st.nextToken();
}
}
tenten