結果

問題 No.1071 ベホマラー
ユーザー _lambda00_lambda00
提出日時 2020-06-07 22:38:24
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 43 ms / 2,000 ms
コード長 1,934 bytes
コンパイル時間 1,182 ms
コンパイル使用メモリ 121,040 KB
実行使用メモリ 4,896 KB
最終ジャッジ日時 2023-08-25 14:03:59
合計ジャッジ時間 3,854 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 35 ms
4,384 KB
testcase_11 AC 34 ms
4,416 KB
testcase_12 AC 23 ms
4,380 KB
testcase_13 AC 30 ms
4,380 KB
testcase_14 AC 39 ms
4,380 KB
testcase_15 AC 42 ms
4,560 KB
testcase_16 AC 42 ms
4,876 KB
testcase_17 AC 42 ms
4,672 KB
testcase_18 AC 43 ms
4,636 KB
testcase_19 AC 41 ms
4,628 KB
testcase_20 AC 40 ms
4,752 KB
testcase_21 AC 39 ms
4,572 KB
testcase_22 AC 39 ms
4,600 KB
testcase_23 AC 39 ms
4,896 KB
testcase_24 AC 42 ms
4,700 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <unordered_map>
#include <queue>
#include <bitset>
#include <limits>

using ld = long double;
using ll = long long int;
using ul = unsigned long long int;

namespace lamlib
{
	/* constant */
	constexpr double epsilon = std::numeric_limits<double>::epsilon();

	/* math */
	template<class T> inline T abs(const T &a){ return (a>0) ? a : -a; }
	ul inline digit(const ul &num){ return static_cast<ul>(std::log10(num+epsilon))+1; }

	/* algorithm */
	ul gcd(const ul &a,const ul &b) { return (!b) ? a : gcd(b,a%b); } // NOTE: a > b
	std::vector<bool> eratosthenes(const ul &n)
	{
		std::vector<bool> prime_candidate(n,true);
		prime_candidate[0] = prime_candidate[1] = false;
		const ul max_n = static_cast<ul>(std::sqrt(n));
		for(ul i = 2;i < max_n;++i)
		{
			if(!prime_candidate[i]) continue;
			for(ul j = 2;i*j < n;++j) prime_candidate[i*j] = false;
		}
		return prime_candidate;
	}

	/* string */
	inline ul same_char_count(const std::string s,const char &ch){ return std::count(std::cbegin(s),std::cend(s),ch); }
}

// std::cout << std::fixed << std::setprecision(15) << std::endl;

int main(int argc,char *argv[])
{
	ll n,k,x,y;
	std::cin >> n >> k >> x >> y;

	std::vector<ll> a(n,0);
	std::vector<ll> need_recover(n,0);
	for(ll i = 0;i < n;++i)
	{
		std::cin >> a[i];
		ll cost = (a[i]-1)/k;
		need_recover[i] = ((a[i]-1)%k != 0) ? cost+1 : cost;
	}
	std::sort(need_recover.begin(),need_recover.end(),std::less<>());
	
	ll ans = 0;
	ll cast_count = 0;
	ll m = n;
	for(ll i = 0;i < n;++i)
	{
		need_recover[i] -= cast_count;
		--m;
		if(need_recover[i] <= 0) continue;
		// ベホマラー
		if(y < (m+1)*x)
		{
			ans += need_recover[i]*y;
			cast_count += need_recover[i];
		}
		// ベホイミ
		else
		{
			ans += need_recover[i]*x;
		}
	}

	std::cout << ans << std::endl;

	return 0;
}
0