結果

問題 No.1071 ベホマラー
ユーザー Mishan5055Mishan5055
提出日時 2020-06-07 00:55:28
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 46 ms / 2,000 ms
コード長 803 bytes
コンパイル時間 677 ms
コンパイル使用メモリ 78,656 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-25 02:28:03
合計ジャッジ時間 2,441 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 36 ms
4,380 KB
testcase_11 AC 36 ms
4,380 KB
testcase_12 AC 24 ms
4,380 KB
testcase_13 AC 32 ms
4,376 KB
testcase_14 AC 40 ms
4,380 KB
testcase_15 AC 46 ms
4,376 KB
testcase_16 AC 43 ms
4,380 KB
testcase_17 AC 45 ms
4,380 KB
testcase_18 AC 44 ms
4,380 KB
testcase_19 AC 46 ms
4,384 KB
testcase_20 AC 42 ms
4,376 KB
testcase_21 AC 43 ms
4,380 KB
testcase_22 AC 40 ms
4,376 KB
testcase_23 AC 43 ms
4,380 KB
testcase_24 AC 45 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cassert>

using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
int main() {
	long long N, K, X, Y;
	cin >> N >> K >> X >> Y;

	vector<long long> A(N, 0);
	int Max = 0;

	rep(i, N) {
		cin >> A.at(i);
		A.at(i)--;
		if (A.at(i) > Max) {
			Max = A.at(i);
		}
	}

	long long ans = 0;

	int S = Y / X;

	long long ZERO = 0;

	if (S >= N) {
		rep(i, N) {
			ans += ((A.at(i) + K - 1) / K)*X;
		}
	}
	else if (S < 1) {
		ans= ((Max + K - 1) / K) * Y;
	}
	else {
		sort(A.begin(),A.end());
		long long beho1 =( (A.at(N - S -1) + K - 1) / K);
		rep(i, N) {
			A.at(i) =std::max(A.at(i)-beho1 * K,ZERO);
		}
		rep(i, N) {
			ans += ((A.at(i) + K - 1) / K) * X;
		}
		ans += beho1 * Y;
	}

	cout << ans << endl;
}
0