結果

問題 No.1071 ベホマラー
ユーザー ks2mks2m
提出日時 2020-06-05 21:48:44
言語 Java19
(openjdk 21)
結果
AC  
実行時間 1,049 ms / 2,000 ms
コード長 1,076 bytes
コンパイル時間 4,475 ms
コンパイル使用メモリ 85,260 KB
実行使用メモリ 71,268 KB
最終ジャッジ日時 2023-08-22 15:02:43
合計ジャッジ時間 17,832 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 126 ms
55,872 KB
testcase_01 AC 125 ms
54,204 KB
testcase_02 AC 126 ms
56,352 KB
testcase_03 AC 124 ms
56,232 KB
testcase_04 AC 127 ms
55,732 KB
testcase_05 AC 127 ms
55,684 KB
testcase_06 AC 132 ms
55,892 KB
testcase_07 AC 140 ms
55,876 KB
testcase_08 AC 138 ms
56,084 KB
testcase_09 AC 127 ms
56,220 KB
testcase_10 AC 930 ms
68,580 KB
testcase_11 AC 889 ms
69,128 KB
testcase_12 AC 753 ms
63,616 KB
testcase_13 AC 832 ms
68,888 KB
testcase_14 AC 914 ms
69,012 KB
testcase_15 AC 1,015 ms
69,344 KB
testcase_16 AC 1,036 ms
68,948 KB
testcase_17 AC 998 ms
68,916 KB
testcase_18 AC 994 ms
69,860 KB
testcase_19 AC 1,049 ms
68,932 KB
testcase_20 AC 627 ms
61,780 KB
testcase_21 AC 629 ms
62,744 KB
testcase_22 AC 619 ms
62,448 KB
testcase_23 AC 634 ms
62,948 KB
testcase_24 AC 958 ms
71,268 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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());
	}
}
0