結果
問題 | No.1687 What the Heck? |
ユーザー |
![]() |
提出日時 | 2021-09-24 21:42:46 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 965 ms / 2,000 ms |
コード長 | 793 bytes |
コンパイル時間 | 2,396 ms |
コンパイル使用メモリ | 80,776 KB |
実行使用メモリ | 65,132 KB |
最終ジャッジ日時 | 2024-07-05 10:18:46 |
合計ジャッジ時間 | 12,837 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 18 |
ソースコード
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; } }