結果

問題 No.1071 ベホマラー
ユーザー forest3forest3
提出日時 2020-06-22 15:03:05
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 50 ms / 2,000 ms
コード長 814 bytes
コンパイル時間 1,813 ms
コンパイル使用メモリ 174,072 KB
実行使用メモリ 6,036 KB
最終ジャッジ日時 2023-09-16 19:14:13
合計ジャッジ時間 4,005 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 42 ms
5,904 KB
testcase_11 AC 41 ms
5,804 KB
testcase_12 AC 27 ms
4,412 KB
testcase_13 AC 37 ms
5,676 KB
testcase_14 AC 43 ms
5,940 KB
testcase_15 AC 49 ms
5,972 KB
testcase_16 AC 49 ms
5,880 KB
testcase_17 AC 49 ms
6,032 KB
testcase_18 AC 49 ms
5,884 KB
testcase_19 AC 49 ms
5,832 KB
testcase_20 AC 43 ms
4,376 KB
testcase_21 AC 43 ms
4,376 KB
testcase_22 AC 44 ms
4,380 KB
testcase_23 AC 44 ms
4,380 KB
testcase_24 AC 50 ms
6,036 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main()
{
	int N;
	long long K, X, Y;
	cin >> N >> K >> X >> Y;
	vector<long long> a( N );
	for( int i = 0; i < N; i++ ) {
		long long A;
		cin >> A;
		a[i] = (A - 1 + K - 1) / K;
	}

	sort( a.begin(), a.end() );
	vector<pair<long long, int>> p;
	int n = 0;
	for( int i = 0; i < N; i++ ) {
		if( i + 1 < N && a[i] == a[i + 1] ) {
			n++;
		}
		else {
			p.push_back( make_pair( a[i], n + 1 ) );
			n = 0;
		}
	}
	n = N;
	for( int i = 0; i < p.size(); i++ ) {
		long long s = p[i].second;
		p[i].second = n;
		n -= s;
	}
	long long ans = 0;
	long long last = 0;
	for( int i = 0; i < p.size(); i++ ) {
		int n = p[i].second;
		long long h = p[i].first - last;
		if( n * X < Y ) ans += n * X * h;
		else ans += Y * h;
		last = p[i].first;
	}

	cout << ans << endl;
}
0