結果
| 問題 |
No.972 選び方のスコア
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-05-29 03:18:01 |
| 言語 | C (gcc 13.3.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 1,079 bytes |
| コンパイル時間 | 450 ms |
| コンパイル使用メモリ | 30,464 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-10-13 19:18:55 |
| 合計ジャッジ時間 | 5,470 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 6 RE * 26 |
ソースコード
//set many funcs template
//Ver.20190820
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<stdbool.h>
#include<time.h>
#include<assert.h>
#define inf 1072114514
#define llinf 4154118101919364364
#define mod 1000000007
#define pi 3.1415926535897932384
#define size 64
long long llmax(long long a,long long b){if(a>b){return a;}return b;}
int llsortfncsj(const void *a,const void *b){if(*(long long *)a>*(long long *)b){return 1;}if(*(long long *)a==*(long long *)b){return 0;}return -1;}
int main(void){
long long i,j,n,m,k,a[size],b,c,h,w,r=0,l,t;
long long rw[size]={0};
long long st,fi,te;
scanf("%lld",&n);
for(i=1;i<=n;i++){
scanf("%lld",&a[i]);
}
qsort(&a[1],n,sizeof(long long),llsortfncsj);
for(i=1;i<=n;i++){rw[i]=rw[i-1]+a[i];}
if(n<=2){puts("0");return 0;}
for(i=2;i<=n-1;i++){
st=1;fi=(i-1);
while(st<=fi){
te=(st+fi)/2;
if(a[n+1-te]+a[i-te]-2*a[i]<0){fi=te-1;}
else{st=te+1;}
}
w=(rw[i]-rw[i-fi-1])+(rw[n]-rw[n-fi]);
r=llmax(w-(2*fi+1)*a[i],r);
}
printf("%lld\n",r);
return 0;
}