結果
| 問題 | No.1071 ベホマラー | 
| コンテスト | |
| ユーザー |  ks2m | 
| 提出日時 | 2020-06-05 21:48:44 | 
| 言語 | Java (openjdk 23) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 1,018 ms / 2,000 ms | 
| コード長 | 1,076 bytes | 
| コンパイル時間 | 2,838 ms | 
| コンパイル使用メモリ | 85,968 KB | 
| 実行使用メモリ | 75,536 KB | 
| 最終ジャッジ日時 | 2024-12-17 14:15:05 | 
| 合計ジャッジ時間 | 17,415 ms | 
| ジャッジサーバーID (参考情報) | judge4 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 5 | 
| other | AC * 20 | 
ソースコード
import java.math.BigInteger;
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();
		BigInteger x = sc.nextBigInteger();
		BigInteger y = sc.nextBigInteger();
		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();
		BigInteger ans = BigInteger.valueOf(sum).multiply(x);
		BigInteger val = ans;
		int pre = 0;
		int rem = n;
		for (int key : map.keySet()) {
			BigInteger d = BigInteger.valueOf(key - pre);
			BigInteger add = d.multiply(y);
			BigInteger sub = d.multiply(x).multiply(BigInteger.valueOf(rem));
			pre = key;
			rem -= map.get(key);
			val = val.add(add).subtract(sub);
			if (val.compareTo(ans) < 0) {
				ans = val;
			}
		}
		System.out.println(ans.toString());
	}
}
            
            
            
        