結果

問題 No.1071 ベホマラー
コンテスト
ユーザー 東前頭十一枚目
提出日時 2020-06-06 04:36:57
言語 C++14
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++14 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 47 ms / 2,000 ms
コード長 677 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 994 ms
コンパイル使用メモリ 183,636 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2026-05-28 06:19:07
合計ジャッジ時間 2,638 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge2_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;

int main() {
	int n; cin >> n;
	int64_t k, x, y; cin >> k >> x >> y;
	int64_t a[n];
	int64_t sum = 0, maxi = 0;
	for(int i = 0; i < n; ++i) {
		cin >> a[i];
		--a[i];
		a[i] = (a[i] + k - 1) / k;
		sum += a[i];
		maxi = max(maxi, a[i]);
	}
	sort(a, a + n);
	int64_t ans = maxi * y;
	if(y >= n * x) {
		ans = min(ans, sum * x);
	}
	int64_t cnt = 0;
	for(int64_t i = 0; i < n; ++i) {
		cnt = a[i];
		sum -= a[i];
		if(y < (n - i - 1) * x) continue;
		int64_t tmp = (sum - cnt * (n - i - 1)) * x + cnt * y;
		ans = min(ans, tmp);
		// cout << cnt << " " << sum << '\n';
		// cout << tmp << '\n';
	}
	cout << ans << '\n';
	return 0;
}
0