結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 AC 70 ms
5,340 KB
testcase_11 AC 74 ms
5,404 KB
testcase_12 AC 76 ms
5,396 KB
testcase_13 AC 74 ms
5,424 KB
testcase_14 AC 77 ms
5,424 KB
testcase_15 AC 75 ms
5,460 KB
testcase_16 AC 74 ms
5,460 KB
testcase_17 AC 77 ms
5,432 KB
testcase_18 RE -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
権限があれば一括ダウンロードができます

ソースコード

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<=20000;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