結果

問題 No.9 モンスターのレベル上げ
ユーザー tenten
提出日時 2020-10-22 16:01:22
言語 Java
(openjdk 23)
結果
AC  
実行時間 814 ms / 5,000 ms
コード長 1,553 bytes
コンパイル時間 2,319 ms
コンパイル使用メモリ 80,724 KB
実行使用メモリ 48,272 KB
最終ジャッジ日時 2024-07-21 09:19:07
合計ジャッジ時間 13,484 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] homes = new int[n];
        for (int i = 0; i < n; i++) {
            homes[i] = sc.nextInt();
        }
        int[] enemies = new int[n];
        for (int i = 0; i < n; i++) {
            enemies[i] = sc.nextInt();
        }
        int min = Integer.MAX_VALUE;
        for (int i = 0; i < n; i++) {
            int max = 0;
            PriorityQueue<Monster> queue = new PriorityQueue<>();
            for (int j = 0; j < n; j++) {
                queue.add(new Monster(homes[j]));
            }
            for (int j = 0; j < n; j++) {
                Monster m = queue.poll();
                m.count++;
                max = Math.max(max, m.count);
                m.value += enemies[(i + j) % n] / 2;
                queue.add(m);
            }
            min = Math.min(min, max);
        }
        System.out.println(min);
    }
    
    static class Monster implements Comparable<Monster> {
        int count;
        int value;
        
        public Monster(int value) {
            this.value = value;
        }
        
        public int compareTo(Monster another) {
            if (value == another.value) {
                return count - another.count;
            } else {
                return value - another.value;
            }
        }
        
        public String toString() {
            return "[" + count + ":" + value + "]";
        }
    }
}
0