結果

問題 No.972 選び方のスコア
ユーザー milanis48663220milanis48663220
提出日時 2020-04-11 22:09:19
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,743 bytes
コンパイル時間 949 ms
コンパイル使用メモリ 86,148 KB
実行使用メモリ 6,836 KB
最終ジャッジ日時 2023-10-19 18:10:28
合計ジャッジ時間 5,034 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 47 ms
6,772 KB
testcase_01 AC 47 ms
6,772 KB
testcase_02 AC 45 ms
6,696 KB
testcase_03 AC 25 ms
6,368 KB
testcase_04 AC 49 ms
6,772 KB
testcase_05 AC 48 ms
6,772 KB
testcase_06 AC 49 ms
6,772 KB
testcase_07 AC 35 ms
6,384 KB
testcase_08 AC 33 ms
6,772 KB
testcase_09 AC 32 ms
6,720 KB
testcase_10 AC 28 ms
6,716 KB
testcase_11 AC 30 ms
6,712 KB
testcase_12 AC 27 ms
6,772 KB
testcase_13 AC 29 ms
6,772 KB
testcase_14 AC 28 ms
6,772 KB
testcase_15 AC 29 ms
6,772 KB
testcase_16 AC 30 ms
6,772 KB
testcase_17 AC 29 ms
6,772 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 3 ms
5,640 KB
testcase_26 AC 2 ms
5,640 KB
testcase_27 AC 3 ms
5,696 KB
testcase_28 AC 2 ms
5,640 KB
testcase_29 AC 2 ms
5,640 KB
testcase_30 AC 2 ms
5,696 KB
testcase_31 AC 2 ms
5,696 KB
testcase_32 AC 3 ms
5,696 KB
testcase_33 WA -
testcase_34 AC 2 ms
5,644 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[0]-2*a[i] < 0){

        }else if(a[N-r]+a[i-r]-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(i-r, i-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[0]-2*m < 0){

        }else if(a[N-r]+a[i-r]-2*m >= 0){
            tmp = calc(i-r, i-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