結果
問題 |
No.972 選び方のスコア
|
ユーザー |
|
提出日時 | 2020-05-29 02:58:04 |
言語 | C (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,110 bytes |
コンパイル時間 | 316 ms |
コンパイル使用メモリ | 31,104 KB |
実行使用メモリ | 9,088 KB |
最終ジャッジ日時 | 2024-10-13 18:53:04 |
合計ジャッジ時間 | 3,038 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 25 WA * 7 |
ソースコード
//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 524288 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}; 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=1;(2*i+1)<=n;i++){ r=llmax(rw[i+1]+rw[n]-rw[n-i]-(2*i+1)*a[i+1],r); } for(i=1;i<=(n/2);i++){ r=llmax(rw[i]+rw[n]-rw[n-i]-i*(a[i]+a[n-i]),r); r=llmax(rw[i+1]+rw[n]-rw[n-i+1]-i*(a[i]+a[i+1]),r); r=llmax(rw[i-1]+rw[n]-rw[n-i-1]-i*(a[n-i+1]+a[n-i]),r); } printf("%lld\n",r); return 0; }