結果

問題 No.1739 Princess vs. Dragoness (& AoE)
ユーザー merlinmerlin
提出日時 2021-11-12 23:25:04
言語 Java21
(openjdk 21)
結果
AC  
実行時間 2,128 ms / 3,000 ms
コード長 1,766 bytes
コンパイル時間 2,380 ms
コンパイル使用メモリ 75,676 KB
実行使用メモリ 70,224 KB
最終ジャッジ日時 2023-08-17 04:05:17
合計ジャッジ時間 43,534 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
49,688 KB
testcase_01 AC 44 ms
49,804 KB
testcase_02 AC 43 ms
49,624 KB
testcase_03 AC 44 ms
49,992 KB
testcase_04 AC 1,655 ms
69,620 KB
testcase_05 AC 2,128 ms
69,992 KB
testcase_06 AC 1,244 ms
69,264 KB
testcase_07 AC 43 ms
49,668 KB
testcase_08 AC 429 ms
67,624 KB
testcase_09 AC 472 ms
66,184 KB
testcase_10 AC 1,027 ms
62,120 KB
testcase_11 AC 668 ms
62,316 KB
testcase_12 AC 114 ms
55,404 KB
testcase_13 AC 1,269 ms
69,212 KB
testcase_14 AC 1,377 ms
69,920 KB
testcase_15 AC 1,222 ms
68,788 KB
testcase_16 AC 1,385 ms
62,184 KB
testcase_17 AC 768 ms
67,752 KB
testcase_18 AC 1,184 ms
64,596 KB
testcase_19 AC 365 ms
60,352 KB
testcase_20 AC 389 ms
59,820 KB
testcase_21 AC 713 ms
66,496 KB
testcase_22 AC 1,143 ms
69,888 KB
testcase_23 AC 2,027 ms
70,224 KB
testcase_24 AC 2,015 ms
68,936 KB
testcase_25 AC 1,804 ms
70,220 KB
testcase_26 AC 1,901 ms
69,976 KB
testcase_27 AC 2,062 ms
69,364 KB
testcase_28 AC 1,917 ms
69,348 KB
testcase_29 AC 2,089 ms
69,188 KB
testcase_30 AC 1,768 ms
69,732 KB
testcase_31 AC 1,933 ms
68,700 KB
testcase_32 AC 1,993 ms
66,988 KB
testcase_33 AC 51 ms
49,928 KB
testcase_34 AC 42 ms
49,680 KB
testcase_35 AC 53 ms
49,612 KB
testcase_36 AC 68 ms
51,584 KB
testcase_37 AC 47 ms
49,572 KB
testcase_38 AC 64 ms
51,380 KB
testcase_39 AC 86 ms
52,484 KB
testcase_40 AC 53 ms
49,840 KB
testcase_41 AC 65 ms
51,888 KB
testcase_42 AC 53 ms
49,584 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;

class Main
{
    public static void main(String args[])throws Exception
    {
        BufferedReader bu=new BufferedReader(new InputStreamReader(System.in));
        StringBuilder sb=new StringBuilder();
        String s[]=bu.readLine().split(" ");
        int n=Integer.parseInt(s[0]),a=Integer.parseInt(s[1]),b=Integer.parseInt(s[2]),x=Integer.parseInt(s[3]),y=Integer.parseInt(s[4]);
        int i,h[]=new int[n];
        s=bu.readLine().split(" ");
        for(i=0;i<n;i++) h[i]=Integer.parseInt(s[i]);

        int l=0,r=(int)1e9,mid,ans=r;
        while(l<=r)
        {
            mid=(l+r)>>1;
            if(possible(h,a,b,x,y,mid))
            {
                ans=mid;
                r=mid-1;
            }
            else l=mid+1;
        }
        System.out.println(ans);
    }

    static boolean possible(int en[],int a,int b,int x,int y,int k)
    {
        int i,n=en.length,h[]=new int[n];
        for(i=0;i<n;i++) h[i]=en[i]-k;

        PriorityQueue<int[]> pq=new PriorityQueue<>(new Comparator<int[]>() {
            @Override
            public int compare(int[] o1, int[] o2) {
                if(o1[0]<o2[0]) return 1;
                else if(o1[0]==o2[0]) return o1[1]>o2[1]?1:-1;
                else return -1;
            }});
        for(i=0;i<n;i++)
        if(h[i]>0) pq.add(new int[]{h[i],i});

        while(a-->0 && !pq.isEmpty())
        {
            int e[]=pq.poll();
            e[0]-=x;
            h[e[1]]-=x;
            if(e[0]>0) pq.add(e);
        }

        long del=1l*b*y;
        for(i=0;i<n;i++)
        {
            long t=Math.max(0,Math.min(h[i],del));
            h[i]-=t;
            del-=t;
            if(h[i]>0) return false;
        }
        return true;
    }
}
0