結果

問題 No.972 選び方のスコア
ユーザー tekihei2317tekihei2317
提出日時 2020-01-18 15:03:21
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 108 ms / 2,000 ms
コード長 591 bytes
コンパイル時間 1,969 ms
コンパイル使用メモリ 169,988 KB
実行使用メモリ 5,724 KB
最終ジャッジ日時 2023-09-09 22:16:07
合計ジャッジ時間 6,259 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 107 ms
5,420 KB
testcase_01 AC 108 ms
5,720 KB
testcase_02 AC 102 ms
5,176 KB
testcase_03 AC 49 ms
4,384 KB
testcase_04 AC 99 ms
5,724 KB
testcase_05 AC 99 ms
5,392 KB
testcase_06 AC 100 ms
5,372 KB
testcase_07 AC 80 ms
5,188 KB
testcase_08 AC 89 ms
5,456 KB
testcase_09 AC 88 ms
5,536 KB
testcase_10 AC 88 ms
5,420 KB
testcase_11 AC 93 ms
5,464 KB
testcase_12 AC 93 ms
5,684 KB
testcase_13 AC 95 ms
5,508 KB
testcase_14 AC 93 ms
5,492 KB
testcase_15 AC 94 ms
5,532 KB
testcase_16 AC 96 ms
5,452 KB
testcase_17 AC 97 ms
5,424 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 95 ms
5,436 KB
testcase_20 AC 95 ms
5,688 KB
testcase_21 AC 95 ms
5,388 KB
testcase_22 AC 95 ms
5,420 KB
testcase_23 AC 95 ms
5,388 KB
testcase_24 AC 94 ms
5,368 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 2 ms
4,384 KB
testcase_30 AC 2 ms
4,376 KB
testcase_31 AC 1 ms
4,380 KB
testcase_32 AC 1 ms
4,380 KB
testcase_33 AC 1 ms
4,380 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 L=i,R=N-(i+1);
      int ok=0,ng=min(L,R)+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