結果

問題 No.1071 ベホマラー
ユーザー chocono2230chocono2230
提出日時 2020-06-05 22:54:58
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 82 ms / 2,000 ms
コード長 1,506 bytes
コンパイル時間 1,739 ms
コンパイル使用メモリ 172,884 KB
実行使用メモリ 8,136 KB
最終ジャッジ日時 2023-08-22 16:52:41
合計ジャッジ時間 3,864 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 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,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 64 ms
7,296 KB
testcase_11 AC 62 ms
7,192 KB
testcase_12 AC 39 ms
5,860 KB
testcase_13 AC 57 ms
6,692 KB
testcase_14 AC 67 ms
7,756 KB
testcase_15 AC 77 ms
8,136 KB
testcase_16 AC 78 ms
8,088 KB
testcase_17 AC 81 ms
8,032 KB
testcase_18 AC 82 ms
8,048 KB
testcase_19 AC 81 ms
8,096 KB
testcase_20 AC 42 ms
4,380 KB
testcase_21 AC 42 ms
4,380 KB
testcase_22 AC 42 ms
4,380 KB
testcase_23 AC 42 ms
4,380 KB
testcase_24 AC 63 ms
8,032 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

ll safell(ll i, ll j){
  if(j != 0 && i > LLONG_MAX / j) return -1;
  return i*j;
}

int main(){
  int n, k, x, y;
  cin >> n >> k >> x >> y;
  vector<int> a(n);
  map<int, int> c;
  ll csum = 0;
  rep(i, n){
    int in;
    cin >> in;
    in--;
    a.at(i) = in;
    c[(in+k-1)/k]++;
    csum += (ll)(in+k-1)/k;
  }
  ll ans = LLONG_MAX;
  ll ux = 0, xc = 0;
  bool f = false;
  rrepit(ritr, c){
    ll add = safell(ritr->first, y);
    if(add == -1){
      f = true;
      break;
    }
    ll ad1 = safell(ux, x);
    if(ad1 == -1){
      f = true;
      break;
    }
    add += ad1;
    if(ans >= add){
      ans = add;
    }else{
      f = true;
      break;
    }
    // cerr << ritr->first << " " << ritr->second << " " << ux << " " << add << endl;
    auto itr = ritr;
    itr++;
    if(itr != c.rend()){
      ll diff = ritr->first - itr->first;
      ux += diff*(ritr->second);
      ux += diff*xc;
      xc += ritr->second;
    }
  }
  if(f == false){
    ll add = safell(x, csum);
    if(add != -1){
      ans = min(ans, add);
    }
  }
  cout << ans << endl;

  return 0;
}
0