結果

問題 No.972 選び方のスコア
ユーザー CleyLCleyL
提出日時 2020-01-17 22:59:05
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 557 bytes
コンパイル時間 766 ms
コンパイル使用メモリ 74,140 KB
実行使用メモリ 4,860 KB
最終ジャッジ日時 2023-09-08 06:28:06
合計ジャッジ時間 4,533 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 93 ms
4,592 KB
testcase_01 AC 93 ms
4,724 KB
testcase_02 AC 89 ms
4,540 KB
testcase_03 AC 43 ms
4,376 KB
testcase_04 AC 85 ms
4,596 KB
testcase_05 AC 84 ms
4,656 KB
testcase_06 AC 85 ms
4,852 KB
testcase_07 AC 70 ms
4,376 KB
testcase_08 AC 75 ms
4,656 KB
testcase_09 AC 72 ms
4,536 KB
testcase_10 AC 76 ms
4,548 KB
testcase_11 AC 81 ms
4,540 KB
testcase_12 AC 81 ms
4,588 KB
testcase_13 AC 82 ms
4,548 KB
testcase_14 AC 81 ms
4,656 KB
testcase_15 AC 81 ms
4,596 KB
testcase_16 AC 83 ms
4,712 KB
testcase_17 AC 83 ms
4,548 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,376 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 2 ms
4,376 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 2 ms
4,380 KB
testcase_33 AC 1 ms
4,380 KB
testcase_34 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
  int n;cin>>n;
  if(n < 3){
    cout << 0 << endl;
    return 0;
  }
  vector<long long> a(n);
  for(int i = 0; n > i; i++){
    cin>>a[i];
  }
  long long ans = 0;
  sort(a.begin(),a.end());
  long long nw = a[0]+a[1];
  long long ce;
  for(int i = 1; i <= n-i; i++){//3,5
    nw += a[n-i];
    ce = a[i];
    ans = max(ans,nw-ce*(i*2+1));
    if(i == n-i)break;
    nw += a[i+1];
    ce = a[i]+a[i+1];
    ans = max(ans,nw-ce*(i+1));
  }
  cout << ans << endl;
}
0