結果
| 問題 | No.1071 ベホマラー | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2020-06-05 21:35:16 | 
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 26 ms / 2,000 ms | 
| コード長 | 612 bytes | 
| コンパイル時間 | 2,008 ms | 
| コンパイル使用メモリ | 198,076 KB | 
| 最終ジャッジ日時 | 2025-01-10 22:14:58 | 
| ジャッジサーバーID (参考情報) | judge3 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 5 | 
| other | AC * 20 | 
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:12:26: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   12 |         lint k,x,y; scanf("%d%lld%lld%lld",&n,&k,&x,&y);
      |                     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
main.cpp:14:23: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   14 |         rep(i,n) scanf("%lld",&a[i]);
      |                  ~~~~~^~~~~~~~~~~~~~
            
            ソースコード
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
using lint=long long;
const long long INF=1LL<<61;
int main(){
	int n;
	lint k,x,y; scanf("%d%lld%lld%lld",&n,&k,&x,&y);
	vector<lint> a(n);
	rep(i,n) scanf("%lld",&a[i]);
	rep(i,n) a[i]=(a[i]-1+k-1)/k;
	sort(a.begin(),a.end());
	vector<lint> cum(n+1);
	rep(i,n) cum[i+1]=cum[i]+a[i];
	lint ans=INF;
	if(cum[n]<=ans/x) ans=cum[n]*x;
	rep(i,n){
		lint cost1=a[i]*y;
		lint cost2=(cum[n]-cum[i+1]-(n-i-1)*a[i]);
		if(cost2>=INF/x) continue;
		cost2*=x;
		ans=min(ans,cost1+cost2);
	}
	printf("%lld\n",ans);
	return 0;
}
            
            
            
        