結果

問題 No.1071 ベホマラー
コンテスト
ユーザー seven_three
提出日時 2020-06-05 21:42:39
言語 C++14
(gcc 13.3.0 + boost 1.89.0)
結果
WA  
実行時間 -
コード長 988 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,077 ms
コンパイル使用メモリ 98,768 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-12-17 13:57:51
合計ジャッジ時間 2,723 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 19 WA * 1
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:48:30: warning: 'z' may be used uninitialized [-Wmaybe-uninitialized]
   48 |                 ans += vec[n - z - 1] * y;
      |                            ~~^~~
main.cpp:33:19: note: 'z' was declared here
   33 |         long long z;
      |                   ^

ソースコード

diff #
raw source code

#include <iostream>
#include <string>
#include <algorithm>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
int main() {
#define int long long
	long long n, k, x, y;
	cin >> n >> k >> x >> y;
	vector<int> vec;
	for (int i = 0; i < n; i++) {
		long long a;
		cin >> a;
		a--;
		if (a != 0) {
			vec.emplace_back((a + k - 1) / k);
		}
	}
	long long z;
	if (vec.empty()) {
		cout << "0" << endl;
		return 0;
	}
	sort(vec.begin(), vec.end());
	for (int i = n; i >= 0; i--) {
		if (y > x * i) {
			z = i;
			break;
		}
	}
	long long ans = 0;
	long long o;
	if (n - z - 1 != -1) {
		ans += vec[n - z - 1] * y;
		o = vec[n - z - 1];
	}
	else {
		o = 0;
	}
	for (int i = n - z; i < n; i++) {
		ans += (vec[i] - o) * x;
	}
	cout << ans << endl;
	return 0;
}
0