結果
問題 |
No.9 モンスターのレベル上げ
|
ユーザー |
![]() |
提出日時 | 2020-01-15 10:07:05 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 807 ms / 5,000 ms |
コード長 | 1,877 bytes |
コンパイル時間 | 2,273 ms |
コンパイル使用メモリ | 77,884 KB |
実行使用メモリ | 59,684 KB |
最終ジャッジ日時 | 2024-12-31 08:33:38 |
合計ジャッジ時間 | 12,408 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 20 |
ソースコード
import java.util.*; import java.math.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[] arr = new int[n]; int[] enemies = new int[n]; for (int i = 0; i < n; i++) { arr[i] = sc.nextInt(); } for (int i = 0; i < n; i++) { enemies[i] = sc.nextInt(); } int min = Integer.MAX_VALUE; for (int i = 0; i < n; i++) { Team team = new Team(arr); int max = 0; for (int j = 0; j < n && max <= min; j++) { int x = enemies[(i + j) % n]; Member m = team.getMember(); m.add(x / 2); max = Math.max(max, m.count); team.add(m); } min = Math.min(min, max); } System.out.println(min); } static class Team { PriorityQueue<Member> queue = new PriorityQueue<>(); public Team (int[] arr) { for (int x : arr) { queue.add(new Member(x)); } } public Member getMember() { return queue.poll(); } public void add(Member m) { queue.add(m); } } static class Member implements Comparable<Member> { int level; int count; public Member(int level) { this.level = level; this.count = 0; } public void add(int added) { level += added; count++; } public int compareTo(Member another) { if (level == another.level) { return count - another.count; } else { return level - another.level; } } } }