結果

問題 No.837 Noelちゃんと星々2
ユーザー ngtkanangtkana
提出日時 2020-03-13 00:43:31
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,347 bytes
コンパイル時間 2,022 ms
コンパイル使用メモリ 208,020 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-30 18:35:21
合計ジャッジ時間 3,581 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h>
#define endl enjoy_codeforces
using lint=long long;
void cmn(lint&x,lint y){if(x>y)x=y;}
lint round_div(lint x, lint y){return x/y+(y/2<x%y);}
int main(){
    std::cin.tie(nullptr);std::ios_base::sync_with_stdio(false);
    int n;std::cin>>n;
    std::vector<lint>a(n);
    for(lint&x:a)std::cin>>x;
    std::sort(a.begin(),a.end());
    if(a.front()==a.back()){
        std::cout<<n/2<<'\n';
        return 0;
    }
    lint N=std::accumulate(a.begin(),a.end(),0ll);
    lint L=0,C=a.at(0),R=a.at(0);
    lint ans=N;
    for(int c=1,l=0,r=1;c<n;C+=a.at(c++)){
        lint lave=round_div(C,c);
        lint rave=round_div(N-C,n-c);
        for(;l<c&&a.at(l)<lave;L+=a.at(l++));
        for(;r<n&&a.at(r)<rave;R+=a.at(r++));
        cmn(ans,
            lave*l-L
            +(C-L)-lave*(c-l)
            +rave*(r-c)-(R-C)
            +(N-R)-rave*(n-r));
    }
    std::cout<<ans<<'\n';
}

/*
 * ひとつにまとめるのであれば、
 * 平均の切り上げ・切り下げのうち近いほうです。
 *
 * 二つですから、ソートして境界を全探索です。
 * 左側と右側それぞれの合計を管理です。
 * すると、目標高さがわかります。
 * 目標高さより小さい部分と、高い部分の境界も管理です。
 *     L: [0, l[
 *     C: [0, c[
 *     R: [0, r[
 */
0