結果

問題 No.972 選び方のスコア
ユーザー recososorecososo
提出日時 2020-01-17 22:06:05
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 671 bytes
コンパイル時間 1,872 ms
コンパイル使用メモリ 169,384 KB
実行使用メモリ 6,440 KB
最終ジャッジ日時 2023-09-08 03:11:12
合計ジャッジ時間 5,932 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 AC 76 ms
6,112 KB
testcase_09 AC 74 ms
5,900 KB
testcase_10 AC 77 ms
6,184 KB
testcase_11 AC 82 ms
6,248 KB
testcase_12 WA -
testcase_13 AC 81 ms
6,136 KB
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 WA -
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 WA -
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 1 ms
4,380 KB
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 1 ms
4,380 KB
testcase_34 AC 2 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    ll n;cin >> n;
    vector<ll> a(n),sum(n);
    for(int i=0;i<n;i++){
        cin >> a[i];
        if(!i){
            sum[i]=a[i];
        }
        else{
            sum[i]=sum[i-1]+a[i];
        }
    }
    sort(a.begin(),a.end());
    ll ans=0;
    for(int k=1;k<=n;k++){
        ll ss,ms;
        if(k%2==1){
            ms=a[(k-1)/2]*k;
            ss=sum[(k-1)/2]+sum[n-1]-sum[n-1-(k-1-(k-1)/2)];
        }
        else{
            ms=(a[k/2-1]+a[k/2])*k/2;
            ss=sum[k/2]+sum[n-1]-sum[n-1-(k-1-k/2)];
        }
        ans=max(ans,ss-ms);
    }
    cout << ans << endl;
}
0