結果

問題 No.1071 ベホマラー
ユーザー Y17Y17
提出日時 2020-06-05 21:53:49
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 88 ms / 2,000 ms
コード長 1,413 bytes
コンパイル時間 1,763 ms
コンパイル使用メモリ 173,160 KB
実行使用メモリ 12,016 KB
最終ジャッジ日時 2023-08-22 15:13:20
合計ジャッジ時間 3,618 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 70 ms
10,592 KB
testcase_11 AC 67 ms
10,428 KB
testcase_12 AC 43 ms
7,996 KB
testcase_13 AC 60 ms
9,500 KB
testcase_14 AC 74 ms
10,860 KB
testcase_15 AC 86 ms
12,008 KB
testcase_16 AC 87 ms
11,944 KB
testcase_17 AC 86 ms
12,000 KB
testcase_18 AC 88 ms
12,016 KB
testcase_19 AC 87 ms
12,008 KB
testcase_20 AC 43 ms
4,480 KB
testcase_21 AC 43 ms
4,376 KB
testcase_22 AC 43 ms
4,456 KB
testcase_23 AC 43 ms
4,376 KB
testcase_24 AC 71 ms
12,012 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#define int long long
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

std::ostream &operator<<(std::ostream &dest, __int128_t value) {
  std::ostream::sentry s(dest);
  if (s) {
    __uint128_t tmp = value < 0 ? -value : value;
    char buffer[128];
    char *d = std::end(buffer);
    do {
      --d;
      *d = "0123456789"[tmp % 10];
      tmp /= 10;
    } while (tmp != 0);
    if (value < 0) {
      --d;
      *d = '-';
    }
    int len = std::end(buffer) - d;
    if (dest.rdbuf()->sputn(d, len) != len) {
      dest.setstate(std::ios_base::badbit);
    }
  }
  return dest;
}

__int128 parse(string &s) {
  __int128 ret = 0;
  for (int i = 0; i < s.length(); i++)
    if ('0' <= s[i] && s[i] <= '9')
      ret = 10 * ret + s[i] - '0';
  return ret;
}

signed main(){
	int n, k, x, y;
	cin >> n >> k >> x >> y;

	int a[100010];
	for(int i = 0;i < n;i++){
		cin >> a[i];
		a[i]--;
	}

	int m = n;
	map<__int128, __int128> mp;

	__int128 cnt = 0;
	for(int i = 0;i < n;i++){
		int tmp = (a[i]+k-1)/k;
		mp[tmp]++; 
		cnt += tmp;
	}

	__int128 ans = cnt * x;

	__int128 old = 0;
	for(auto e : mp){
		cnt -= m * (e.first-old);
		old = e.first;
		m -= e.second;
		chmin(ans, x*cnt + y*e.first);
	}

	cout << ans << endl;

	return 0;
}
0