結果

問題 No.1071 ベホマラー
ユーザー ks2m
提出日時 2020-06-05 21:36:08
言語 Java
(openjdk 23)
結果
WA  
実行時間 -
コード長 846 bytes
コンパイル時間 2,192 ms
コンパイル使用メモリ 79,352 KB
実行使用メモリ 75,520 KB
最終ジャッジ日時 2024-12-17 13:42:16
合計ジャッジ時間 15,662 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 13 WA * 7
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;
import java.util.TreeMap;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		int x = sc.nextInt();
		int y = sc.nextInt();
		TreeMap<Integer, Integer> map = new TreeMap<>();
		long sum = 0;
		for (int i = 0; i < n; i++) {
			int a = sc.nextInt();
			int b = (a + k - 2) / k;
			if (map.containsKey(b)) {
				map.put(b, map.get(b) + 1);
			} else {
				map.put(b, 1);
			}
			sum += b;
		}
		sc.close();

		long ans = sum * x;
		long val = ans;
		int pre = 0;
		int rem = n;
		for (int key : map.keySet()) {
			long d = key - pre;
			long add = d * y;
			long sub = d * rem * x;
			pre = key;
			rem -= map.get(key);
			val += add - sub;
			ans = Math.min(ans, val);
		}
		System.out.println(ans);
	}
}
0