結果

問題 No.1736 Princess vs. Dragoness
ユーザー merlinmerlin
提出日時 2021-11-12 23:20:42
言語 Java21
(openjdk 21)
結果
AC  
実行時間 91 ms / 2,000 ms
コード長 1,831 bytes
コンパイル時間 2,615 ms
コンパイル使用メモリ 75,416 KB
実行使用メモリ 52,152 KB
最終ジャッジ日時 2023-08-17 03:56:00
合計ジャッジ時間 6,836 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 46 ms
49,488 KB
testcase_01 AC 46 ms
49,608 KB
testcase_02 AC 47 ms
49,632 KB
testcase_03 AC 56 ms
49,788 KB
testcase_04 AC 75 ms
50,592 KB
testcase_05 AC 49 ms
50,008 KB
testcase_06 AC 73 ms
51,496 KB
testcase_07 AC 88 ms
51,944 KB
testcase_08 AC 68 ms
50,528 KB
testcase_09 AC 70 ms
51,808 KB
testcase_10 AC 45 ms
49,404 KB
testcase_11 AC 91 ms
52,152 KB
testcase_12 AC 76 ms
50,496 KB
testcase_13 AC 72 ms
51,480 KB
testcase_14 AC 80 ms
51,788 KB
testcase_15 AC 62 ms
50,640 KB
testcase_16 AC 57 ms
49,576 KB
testcase_17 AC 86 ms
51,948 KB
testcase_18 AC 84 ms
51,748 KB
testcase_19 AC 81 ms
51,916 KB
testcase_20 AC 53 ms
49,784 KB
testcase_21 AC 67 ms
50,852 KB
testcase_22 AC 72 ms
51,760 KB
testcase_23 AC 65 ms
51,508 KB
testcase_24 AC 49 ms
49,380 KB
testcase_25 AC 58 ms
50,176 KB
testcase_26 AC 74 ms
51,484 KB
testcase_27 AC 81 ms
51,404 KB
testcase_28 AC 66 ms
51,848 KB
testcase_29 AC 63 ms
50,744 KB
testcase_30 AC 76 ms
50,756 KB
testcase_31 AC 77 ms
50,816 KB
testcase_32 AC 68 ms
51,048 KB
testcase_33 AC 45 ms
49,896 KB
testcase_34 AC 45 ms
49,512 KB
testcase_35 AC 44 ms
49,532 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;
        }*/
        if(possible(h,a,b,x,y,0)) sb.append("Yes\n");
        else sb.append("No\n");
        System.out.print(sb);
    }

    static boolean possible(int h[],int a,int b,int x,int y,int k)
    {
        int i,n=h.length;
        for(i=0;i<n;i++) h[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