結果

問題 No.1071 ベホマラー
ユーザー htensai
提出日時 2020-06-10 08:29:06
言語 Java
(openjdk 23)
結果
AC  
実行時間 889 ms / 2,000 ms
コード長 691 bytes
コンパイル時間 3,783 ms
コンパイル使用メモリ 84,664 KB
実行使用メモリ 68,160 KB
最終ジャッジ日時 2024-06-13 00:38:26
合計ジャッジ時間 18,510 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
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 k = sc.nextInt();
		int x = sc.nextInt();
		int y = sc.nextInt();
		PriorityQueue<Integer> queue = new PriorityQueue<>();
		for (int i = 0; i < n; i++) {
		    queue.add(sc.nextInt());
		}
		int base = 1;
		long total = 0;
		while (queue.size() > 0) {
		    int z = queue.peek();
		    int count = (z - base + k - 1) / k;
		    if (queue.size() > y / x) {
		        base += count * k;
		        total += (long)count * y;
		    } else {
		        total += (long)count * x;
		    }
		    queue.poll();
		}
		System.out.println(total);
	}
}
0