結果
問題 |
No.1739 Princess vs. Dragoness (& AoE)
|
ユーザー |
![]() |
提出日時 | 2021-11-12 23:25:04 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 1,858 ms / 3,000 ms |
コード長 | 1,766 bytes |
コンパイル時間 | 2,200 ms |
コンパイル使用メモリ | 78,388 KB |
実行使用メモリ | 58,628 KB |
最終ジャッジ日時 | 2024-11-25 21:43:33 |
合計ジャッジ時間 | 37,036 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 40 |
ソースコード
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; } }