結果

問題 No.2627 Unnatural Pitch
ユーザー kokoseikokosei
提出日時 2024-02-09 22:53:16
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 762 bytes
コンパイル時間 2,432 ms
コンパイル使用メモリ 244,876 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-02-09 22:53:24
合計ジャッジ時間 7,363 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,676 KB
testcase_01 AC 1 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 1 ms
6,676 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 288 ms
6,676 KB
testcase_08 AC 269 ms
6,676 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 6 ms
6,676 KB
testcase_12 AC 6 ms
6,676 KB
testcase_13 WA -
testcase_14 AC 6 ms
6,676 KB
testcase_15 AC 4 ms
6,676 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 130 ms
6,676 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int N, K;
ll L, U, A[201010];
ll f(ll k){
    if(k < 0)return 1e18;
    ll cnt = 0;
    for(int i = 0;i < N;i++){
        if(A[i] < k){
            cnt += (k - A[i] + K - 1) / K;
        }
        if(A[i] > k + U - L){
            cnt += (A[i] - (k + U - L) + K - 1) / K;
        }
    }
    return cnt;
}
int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    cin >> N >> K >> L >> U;
    for(int i = 0;i < N;i++)cin >> A[i];
    ll l = 0, r = 1e12;
    while(r - l > 2){
        ll m1 = (l + l + r) / 3;
        ll m2 = (l + r + r) / 3;
        if(f(m1) >= f(m2))l = m1;
        else r = m2;
    }
    cout << min({f(l), f(l + 1), f(l + 2)}) << endl;
    return 0;
}
0