結果

問題 No.972 選び方のスコア
ユーザー GetDigit()GetDigit()
提出日時 2022-11-04 21:19:49
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,205 bytes
コンパイル時間 1,766 ms
コンパイル使用メモリ 169,308 KB
実行使用メモリ 5,636 KB
最終ジャッジ日時 2023-09-25 23:31:13
合計ジャッジ時間 5,289 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 91 ms
5,396 KB
testcase_01 AC 91 ms
5,636 KB
testcase_02 AC 87 ms
5,196 KB
testcase_03 AC 42 ms
4,380 KB
testcase_04 AC 83 ms
5,444 KB
testcase_05 AC 84 ms
5,416 KB
testcase_06 AC 83 ms
5,356 KB
testcase_07 AC 69 ms
4,844 KB
testcase_08 AC 73 ms
5,368 KB
testcase_09 AC 70 ms
5,408 KB
testcase_10 AC 76 ms
5,384 KB
testcase_11 AC 78 ms
5,420 KB
testcase_12 AC 79 ms
5,408 KB
testcase_13 AC 78 ms
5,368 KB
testcase_14 AC 79 ms
5,436 KB
testcase_15 AC 79 ms
5,596 KB
testcase_16 AC 80 ms
5,340 KB
testcase_17 AC 82 ms
5,432 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 1 ms
4,380 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 1 ms
4,376 KB
testcase_30 AC 2 ms
4,376 KB
testcase_31 AC 1 ms
4,376 KB
testcase_32 AC 1 ms
4,376 KB
testcase_33 AC 1 ms
4,376 KB
testcase_34 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

long odd_max(int k,int N,vector<int>& a,vector<long>& a_sum){
    int index = k/2;
    int left = k/2 + 1;
    int right = N  - k/2;
    int mid = a[index];
    long ans = a_sum[N] - a_sum[right] + a_sum[left] - (long)k * (long)mid;
    return ans;
}

long even_max(int k,int N,vector<int>& a,vector<long>& a_sum){
    int index1 = k/2 - 1;
    int index2 = k/2;
    int left = k/2 + 1;
    int right = N + 1 - k/2;
    int mid2 = a[index1] + a[index2];
    long ans = a_sum[N] - a_sum[right] + a_sum[left] - (long)k * (long)mid2 / 2;
    return ans;
}

int main(){
    int N;
    cin >> N;
    vector<int> a(N,0);
    vector<long> a_sum(N+1,0);
    for(int i=0;i<N;i++){
        cin >> a[i];
    }
    sort(a.begin(),a.end());
    for(int i=0;i<N;i++){
        a_sum[i+1] = a_sum[i] + a[i];
    }
    long max = 0;
    long temp;
    for(int i=1;i<=N;i++){
        if(i % 2 == 0){
            temp = even_max(i,N,a,a_sum);
            if(max <= temp){
                max = temp;
            }
        } else {
            temp = odd_max(i,N,a,a_sum);
            if(max <= temp){
                max = temp;
            }
        }
    }
    cout << max;
}
0