結果

問題 No.972 選び方のスコア
ユーザー tko919tko919
提出日時 2020-01-17 23:32:16
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 61 ms / 2,000 ms
コード長 1,034 bytes
コンパイル時間 1,713 ms
コンパイル使用メモリ 171,116 KB
実行使用メモリ 6,452 KB
最終ジャッジ日時 2023-09-08 07:58:19
合計ジャッジ時間 4,840 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 61 ms
6,276 KB
testcase_01 AC 61 ms
6,240 KB
testcase_02 AC 58 ms
6,164 KB
testcase_03 AC 30 ms
4,576 KB
testcase_04 AC 60 ms
6,452 KB
testcase_05 AC 60 ms
6,100 KB
testcase_06 AC 60 ms
6,100 KB
testcase_07 AC 45 ms
5,364 KB
testcase_08 AC 48 ms
6,160 KB
testcase_09 AC 46 ms
5,840 KB
testcase_10 AC 44 ms
6,320 KB
testcase_11 AC 46 ms
6,208 KB
testcase_12 AC 46 ms
6,192 KB
testcase_13 AC 47 ms
6,208 KB
testcase_14 AC 46 ms
6,276 KB
testcase_15 AC 48 ms
6,240 KB
testcase_16 AC 48 ms
6,276 KB
testcase_17 AC 48 ms
6,204 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 59 ms
6,328 KB
testcase_20 AC 58 ms
6,132 KB
testcase_21 AC 58 ms
6,428 KB
testcase_22 AC 57 ms
5,832 KB
testcase_23 AC 59 ms
6,268 KB
testcase_24 AC 58 ms
6,304 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 1 ms
4,376 KB
testcase_30 AC 1 ms
4,380 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 1 ms
4,376 KB
testcase_33 AC 1 ms
4,380 KB
testcase_34 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
void tostr(ll x,string& res){while(x)res+=('0'+(x%10)),x/=10; reverse(ALL(res)); return;}
template<class T> inline bool chmax(T& a,T b){ if(a<b){a=b;return 1;}return 0; }
template<class T> inline bool chmin(T& a,T b){ if(a>b){a=b;return 1;}return 0; }
//template end



int main(){
   int n; scanf("%d",&n);
   vector<ll> a(n);
   rep(i,0,n)scanf("%lld",&a[i]);
   sort(ALL(a));
   vector<ll> b(n+1,0);
   rep(i,0,n)b[i+1]=b[i]+a[i];
   ll res=0;
   rep(i,0,n){
      int lb=0,rb=i+1;
      while(rb-lb>1){
         int mid=(lb+rb)/2;
         if(a[i]-a[i-mid]<a[n-mid]-a[i])lb=mid;
         else rb=mid;
      }
      chmax(res,b[i]-b[i-lb]+b[n]-b[n-lb]-a[i]*lb*2);
   }
   printf("%lld\n",res);
   return 0;
}
0