結果

問題 No.972 選び方のスコア
ユーザー milanis48663220milanis48663220
提出日時 2020-04-11 22:03:37
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,743 bytes
コンパイル時間 1,489 ms
コンパイル使用メモリ 86,332 KB
実行使用メモリ 6,804 KB
最終ジャッジ日時 2023-10-19 18:00:06
合計ジャッジ時間 3,640 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 56 ms
6,768 KB
testcase_01 AC 57 ms
6,768 KB
testcase_02 AC 54 ms
6,656 KB
testcase_03 AC 29 ms
5,252 KB
testcase_04 AC 57 ms
6,768 KB
testcase_05 AC 57 ms
6,768 KB
testcase_06 AC 57 ms
6,768 KB
testcase_07 AC 42 ms
6,032 KB
testcase_08 AC 42 ms
6,768 KB
testcase_09 AC 40 ms
6,704 KB
testcase_10 AC 27 ms
6,716 KB
testcase_11 AC 28 ms
6,712 KB
testcase_12 AC 29 ms
6,768 KB
testcase_13 AC 29 ms
6,768 KB
testcase_14 AC 29 ms
6,768 KB
testcase_15 AC 41 ms
6,768 KB
testcase_16 AC 38 ms
6,768 KB
testcase_17 AC 38 ms
6,768 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 2 ms
5,028 KB
testcase_26 AC 2 ms
5,156 KB
testcase_27 AC 2 ms
5,028 KB
testcase_28 AC 2 ms
5,092 KB
testcase_29 AC 2 ms
4,972 KB
testcase_30 AC 2 ms
4,972 KB
testcase_31 AC 2 ms
4,972 KB
testcase_32 AC 2 ms
5,028 KB
testcase_33 AC 2 ms
5,092 KB
testcase_34 AC 2 ms
4,972 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;
int N;
ll a[200000];
ll sum[200001];

ll calc(int l, int r){
    return sum[r+1]-sum[l];
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    ll ans = 0;
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> a[i];
        a[i] *= 2;
    }
    sort(a, a+N);
    for(int i = 0; i < N; i++) sum[i+1] = sum[i]+a[i];
    for(int i = 1; i <= N-2; i++){
        int n_left = i;
        int n_right = N-i-1;
        int l = 1;
        int r = min(n_left, n_right);
        ll tmp = 0;
        if(a[N-1]+a[i-1]-2*a[i] < 0){

        }else if(a[N-r]+a[r-1]-2*a[i] >= 0){
            tmp = calc(0, r-1)+calc(N-r, N-1)-2*r*a[i]; 
        }else{
            while(r-l > 1){
                int c = (l+r)/2;
                if(a[N-c]+a[c-1]-2*a[i] >= 0) l = c;
                else r = c;
            }
            tmp = calc(0, l-1)+calc(N-l, N-1)-2*l*a[i];
        }
        ans = max(ans, tmp);
    }
    for(int i = 1; i <= N-3; i++){
        int n_left = i;
        int n_right = N-i-2;
        int l = 1;
        int r = min(n_left, n_right);
        ll m = (a[i]+a[i+1])/2;
        ll tmp = 0;
        if(a[N-1]+a[i-1]-2*m < 0){

        }else if(a[N-r]+a[r-1]-2*m >= 0){
            tmp = calc(0, r-1)+calc(N-r, N-1)-2*r*m; 
        }else{
            while(r-l > 1){
                int c = (l+r)/2;
                if(a[N-c]+a[c-1]-2*m >= 0) l = c;
                else r = c;
            }
            tmp = calc(0, l-1)+calc(N-l, N-1)-2*l*m;
        }
        ans = max(ans, tmp);
    }
    cout << ans/2 << endl;
}
0