結果

問題 No.972 選び方のスコア
ユーザー tekihei2317tekihei2317
提出日時 2020-01-17 22:13:09
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 107 ms / 2,000 ms
コード長 572 bytes
コンパイル時間 1,541 ms
コンパイル使用メモリ 171,792 KB
実行使用メモリ 5,656 KB
最終ジャッジ日時 2023-09-08 03:37:36
合計ジャッジ時間 5,698 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 107 ms
5,408 KB
testcase_01 AC 107 ms
5,364 KB
testcase_02 AC 102 ms
5,148 KB
testcase_03 AC 50 ms
4,376 KB
testcase_04 AC 100 ms
5,536 KB
testcase_05 AC 99 ms
5,448 KB
testcase_06 AC 100 ms
5,356 KB
testcase_07 AC 80 ms
4,920 KB
testcase_08 AC 89 ms
5,460 KB
testcase_09 AC 85 ms
5,496 KB
testcase_10 AC 87 ms
5,392 KB
testcase_11 AC 92 ms
5,548 KB
testcase_12 AC 93 ms
5,500 KB
testcase_13 AC 94 ms
5,448 KB
testcase_14 AC 94 ms
5,656 KB
testcase_15 AC 96 ms
5,408 KB
testcase_16 AC 95 ms
5,496 KB
testcase_17 AC 96 ms
5,416 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 95 ms
5,444 KB
testcase_20 AC 95 ms
5,404 KB
testcase_21 AC 94 ms
5,356 KB
testcase_22 AC 95 ms
5,440 KB
testcase_23 AC 94 ms
5,408 KB
testcase_24 AC 94 ms
5,352 KB
testcase_25 AC 1 ms
4,384 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 1 ms
4,380 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 2 ms
4,376 KB
testcase_33 AC 2 ms
4,384 KB
testcase_34 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

using Lint=long long;

int main()
{
   int N; cin>>N;
   vector<int> a(N);
   for(int i=0;i<N;i++) cin>>a[i];
   sort(a.begin(),a.end());

   vector<Lint> sum(N+1);
   for(int i=0;i<N;i++) sum[i+1]=sum[i]+a[i];

   Lint ans=0;
   for(int i=0;i<N;i++){
      int ok=0,ng=min(i,N-(i+1))+1;
      while(ng-ok>1){
         int mid=(ok+ng)/2;
         if(a[i-mid]+a[N-mid]-2*a[i]>0) ok=mid;
         else ng=mid;
      }
      ans=max(ans,(sum[i]-sum[i-ok])+(sum[N]-sum[N-ok]-2LL*ok*a[i]));
   }
   cout<<ans<<endl;
   return 0;
}
0