結果

問題 No.1391 ±1 Abs Sum
ユーザー 👑 NachiaNachia
提出日時 2021-02-12 22:10:40
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 615 bytes
コンパイル時間 2,027 ms
コンパイル使用メモリ 199,800 KB
実行使用メモリ 5,316 KB
最終ジャッジ日時 2023-09-27 04:23:45
合計ジャッジ時間 7,076 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 WA -
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 WA -
testcase_06 AC 2 ms
4,380 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 AC 18 ms
4,504 KB
testcase_15 AC 19 ms
4,608 KB
testcase_16 AC 23 ms
4,780 KB
testcase_17 AC 21 ms
4,712 KB
testcase_18 AC 27 ms
5,084 KB
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 AC 30 ms
5,316 KB
testcase_32 AC 17 ms
4,376 KB
testcase_33 AC 18 ms
4,400 KB
testcase_34 RE -
testcase_35 AC 1 ms
4,384 KB
testcase_36 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using LL=long long;
using ULL=unsigned long long;
#define rep(i,n) for(int i=0; i<(n); i++)



int N,K;
LL A[200000];

LL solve(){
  LL ans=0;
  if(K*2<=N){
    rep(i,K) ans+=(A[i]-A[0])*2;
    rep(i,N) ans+=A[0]-A[i];
    return ans;
  }
  LL pibot = (N-K-K-1)/2;
  LL x=A[pibot];
  rep(i,pibot) ans+=(x-A[i])*2;
  rep(i,K) ans+=(A[i]-x)*2;
  rep(i,N) ans+=x-A[i];
  return ans;
}

int main(){
  scanf("%d%d",&N,&K);
  rep(i,N) scanf("%lld",&A[i]);
  LL ans=solve();
  reverse(A,A+N); rep(i,N) A[i]=-A[i];
  ans=min(ans,solve());
  printf("%lld\n",ans);
  return 0;
}
0