結果

問題 No.837 Noelちゃんと星々2
ユーザー NacoNaco
提出日時 2019-07-02 15:50:27
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 673 bytes
コンパイル時間 921 ms
コンパイル使用メモリ 63,684 KB
実行使用メモリ 4,564 KB
最終ジャッジ日時 2023-09-29 17:04:06
合計ジャッジ時間 3,969 ms
ジャッジサーバーID
(参考情報)
judge14 / 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 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 2 ms
4,376 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 2 ms
4,380 KB
testcase_17 WA -
testcase_18 AC 2 ms
4,380 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 2 ms
4,376 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 WA -
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;

int main(){
    int N;
    cin >> N;
    int Y[N];
    for(int i=0;i<N;i++){
        cin >> Y[i];
    }
    sort(Y,Y+N);
    int j;
    int mx=0;
    for(int i=0;i<N-1;i++){
        if(Y[i+1]-Y[i]>=mx){
            mx=Y[i+1]-Y[i];
            //cout << mx << endl;
            j=i;
        }
    }
    if(mx==0){
        cout << 1 << endl;
        return 0;
    }
    //cout << j << endl;
    long long ans=0;
    int f=j/2;
    int b=(N+j)/2;
    for(int i=0;i<=j;i++){
        ans+=abs(Y[i]-Y[f]);
    }
    for(int i=j+1;i<N;i++){
        ans+=abs(Y[i]-Y[b]);
    }
    cout << ans << endl;
}
0