結果

問題 No.1687 What the Heck?
ユーザー ks2mks2m
提出日時 2021-09-24 21:42:46
言語 Java19
(openjdk 21)
結果
AC  
実行時間 986 ms / 2,000 ms
コード長 793 bytes
コンパイル時間 4,072 ms
コンパイル使用メモリ 78,124 KB
実行使用メモリ 71,352 KB
最終ジャッジ日時 2023-09-18 21:01:42
合計ジャッジ時間 14,812 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 132 ms
55,724 KB
testcase_01 AC 129 ms
55,852 KB
testcase_02 AC 129 ms
55,948 KB
testcase_03 AC 127 ms
55,856 KB
testcase_04 AC 128 ms
56,068 KB
testcase_05 AC 129 ms
56,056 KB
testcase_06 AC 129 ms
55,728 KB
testcase_07 AC 616 ms
62,940 KB
testcase_08 AC 728 ms
65,372 KB
testcase_09 AC 608 ms
62,752 KB
testcase_10 AC 499 ms
61,084 KB
testcase_11 AC 514 ms
60,788 KB
testcase_12 AC 936 ms
71,260 KB
testcase_13 AC 971 ms
71,056 KB
testcase_14 AC 969 ms
70,972 KB
testcase_15 AC 986 ms
71,352 KB
testcase_16 AC 966 ms
71,076 KB
testcase_17 AC 322 ms
60,088 KB
testcase_18 AC 983 ms
71,248 KB
testcase_19 AC 206 ms
58,892 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		PriorityQueue<Obj> que = new PriorityQueue<>((o1, o2) -> o2.p - o1.p);
		for (int i = 0; i < n; i++) {
			Obj o = new Obj();
			o.i = i + 1;
			o.p = sc.nextInt();
			que.add(o);
		}
		sc.close();

		long val = (long) n * (n + 1) / 2;
		Obj o = que.peek();
		long ans = val - o.i * 2;

		while (!que.isEmpty()) {
			Obj cur = que.poll();
			val -= cur.i;
			if (que.isEmpty()) {
				ans = Math.max(ans, val);
			} else {
				Obj next = que.peek();
				long val2 = val - next.i * 2;
				ans = Math.max(ans, val2);
			}
		}
		System.out.println(ans);
	}

	static class Obj {
		int i, p;
	}
}
0