結果

問題 No.1736 Princess vs. Dragoness
ユーザー merlinmerlin
提出日時 2021-11-12 22:55:24
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 2,597 bytes
コンパイル時間 2,527 ms
コンパイル使用メモリ 78,892 KB
実行使用メモリ 39,816 KB
最終ジャッジ日時 2024-05-04 10:33:42
合計ジャッジ時間 6,834 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 54 ms
37,140 KB
testcase_01 AC 52 ms
37,104 KB
testcase_02 AC 53 ms
36,980 KB
testcase_03 AC 62 ms
37,204 KB
testcase_04 WA -
testcase_05 AC 55 ms
37,000 KB
testcase_06 AC 95 ms
38,192 KB
testcase_07 WA -
testcase_08 AC 88 ms
38,148 KB
testcase_09 AC 100 ms
38,892 KB
testcase_10 AC 53 ms
36,860 KB
testcase_11 AC 86 ms
38,324 KB
testcase_12 AC 90 ms
38,328 KB
testcase_13 AC 97 ms
38,452 KB
testcase_14 AC 98 ms
38,260 KB
testcase_15 AC 67 ms
37,316 KB
testcase_16 WA -
testcase_17 AC 96 ms
38,416 KB
testcase_18 AC 92 ms
38,388 KB
testcase_19 AC 85 ms
38,300 KB
testcase_20 AC 58 ms
36,788 KB
testcase_21 AC 85 ms
37,976 KB
testcase_22 AC 97 ms
38,888 KB
testcase_23 AC 84 ms
38,288 KB
testcase_24 AC 55 ms
37,092 KB
testcase_25 AC 56 ms
36,876 KB
testcase_26 AC 87 ms
38,196 KB
testcase_27 AC 79 ms
38,524 KB
testcase_28 AC 80 ms
38,272 KB
testcase_29 AC 78 ms
38,152 KB
testcase_30 AC 94 ms
38,480 KB
testcase_31 WA -
testcase_32 AC 107 ms
38,480 KB
testcase_33 AC 59 ms
37,064 KB
testcase_34 AC 55 ms
36,880 KB
testcase_35 AC 56 ms
36,716 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]);

        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;

        TreeMap<Integer,Integer> tm=new TreeMap<>();
        long del=1l*b*y; int sz=0;
        for(i=0;i<n;i++)
        if(h[i]>0)
        {
            long tem=Math.min(del,h[i]);    //use y values here
            del-=tem;
            h[i]-=tem;

            long ti=tem/x;
            while(ti-->0)
            {
                if(sz<a)
                {
                    sz++;
                    tm.put(x,tm.getOrDefault(x,0)+1);
                }
                else if(sz==a)
                {
                    int lo=tm.higherKey(-1);
                    if(lo<x)
                    {
                        remove(tm,lo);
                        tm.put(x,tm.getOrDefault(x,0)+1);
                    }
                    else break;
                }
                else break;
            }
            if(tem%x!=0 && sz<a)
            {
                sz++;
                tm.put((int)(tem%x),tm.getOrDefault((int)(tem%x),0)+1);    //these can be moves of a
            }

            while(h[i]>del && !tm.isEmpty())
            {
                int key=tm.lowerKey(x+1);
                del+=key;
                remove(tm,key);
                a--;    //using a
                sz--;
            }

            tem=Math.min(h[i],del);
            del-=tem;
            h[i]-=tem;

            //still now h[i]>0
            ti=h[i]/x;
            if(h[i]%x!=0) ti++;
            if(ti>a) return false;
            a-=ti;

            while(sz>a)
            {
                int lo=tm.higherKey(-1);
                remove(tm,lo);
                sz--;
            }
        }
        return true;
    }

    static void remove(TreeMap<Integer,Integer> tm,int x)
    {
        int v=tm.get(x);
        if(v==1) tm.remove(x);
        else tm.put(x,v-1);
    }
}
0