結果

問題 No.1150 シュークリームゲーム(Easy)
ユーザー ks2mks2m
提出日時 2020-08-07 22:00:31
言語 Java21
(openjdk 21)
結果
AC  
実行時間 245 ms / 2,000 ms
コード長 1,182 bytes
コンパイル時間 3,678 ms
コンパイル使用メモリ 84,528 KB
実行使用メモリ 64,376 KB
最終ジャッジ日時 2023-10-25 01:04:12
合計ジャッジ時間 12,013 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 54 ms
53,580 KB
testcase_01 AC 54 ms
53,596 KB
testcase_02 AC 55 ms
53,596 KB
testcase_03 AC 54 ms
53,592 KB
testcase_04 AC 54 ms
53,580 KB
testcase_05 AC 54 ms
53,580 KB
testcase_06 AC 56 ms
53,612 KB
testcase_07 AC 55 ms
53,588 KB
testcase_08 AC 54 ms
53,584 KB
testcase_09 AC 54 ms
53,584 KB
testcase_10 AC 54 ms
53,580 KB
testcase_11 AC 55 ms
53,596 KB
testcase_12 AC 55 ms
53,536 KB
testcase_13 AC 54 ms
51,808 KB
testcase_14 AC 53 ms
53,592 KB
testcase_15 AC 56 ms
53,596 KB
testcase_16 AC 57 ms
53,588 KB
testcase_17 AC 55 ms
53,604 KB
testcase_18 AC 54 ms
53,600 KB
testcase_19 AC 54 ms
53,604 KB
testcase_20 AC 55 ms
53,600 KB
testcase_21 AC 55 ms
53,600 KB
testcase_22 AC 235 ms
61,736 KB
testcase_23 AC 240 ms
63,264 KB
testcase_24 AC 240 ms
63,812 KB
testcase_25 AC 234 ms
64,340 KB
testcase_26 AC 232 ms
62,100 KB
testcase_27 AC 238 ms
63,948 KB
testcase_28 AC 239 ms
63,504 KB
testcase_29 AC 237 ms
63,952 KB
testcase_30 AC 240 ms
63,700 KB
testcase_31 AC 235 ms
64,004 KB
testcase_32 AC 238 ms
64,124 KB
testcase_33 AC 240 ms
64,376 KB
testcase_34 AC 232 ms
64,248 KB
testcase_35 AC 226 ms
63,816 KB
testcase_36 AC 243 ms
63,384 KB
testcase_37 AC 234 ms
64,220 KB
testcase_38 AC 230 ms
64,116 KB
testcase_39 AC 244 ms
63,740 KB
testcase_40 AC 234 ms
63,700 KB
testcase_41 AC 241 ms
63,920 KB
testcase_42 AC 239 ms
63,820 KB
testcase_43 AC 217 ms
63,688 KB
testcase_44 AC 245 ms
63,324 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Collections;
import java.util.PriorityQueue;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		String[] sa = br.readLine().split(" ");
		int s = Integer.parseInt(sa[0]) - 1;
		int t = Integer.parseInt(sa[1]) - 1;
		sa = br.readLine().split(" ");
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = Integer.parseInt(sa[i]);
		}
		br.close();

		long x = 0;
		long y = 0;
		PriorityQueue<Integer> que = new PriorityQueue<>(Collections.reverseOrder());
		for (int i = 0; i < n; i++) {
			int ds = Math.min(Math.min(Math.abs(i - s), Math.abs(n + i - s)),
					Math.abs(n + s - i));
			int dt = Math.min(Math.min(Math.abs(i - t), Math.abs(n + i - t)),
					Math.abs(n + t - i));
			if (ds < dt) x += a[i];
			if (ds > dt) y += a[i];
			if (ds == dt) que.add(a[i]);
		}
		boolean fs = true;
		while (!que.isEmpty()) {
			if (fs) {
				x += que.poll();
			} else {
				y += que.poll();
			}
			fs = !fs;
		}
		System.out.println(x - y);
	}
}
0