結果

問題 No.1391 ±1 Abs Sum
ユーザー 👑 NachiaNachia
提出日時 2021-02-12 22:14:34
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 570 bytes
コンパイル時間 1,706 ms
コンパイル使用メモリ 199,152 KB
実行使用メモリ 5,148 KB
最終ジャッジ日時 2023-09-27 04:31:53
合計ジャッジ時間 3,900 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 27 ms
5,148 KB
testcase_12 AC 21 ms
4,712 KB
testcase_13 AC 24 ms
5,012 KB
testcase_14 AC 15 ms
4,460 KB
testcase_15 AC 15 ms
4,464 KB
testcase_16 AC 20 ms
4,700 KB
testcase_17 AC 18 ms
4,548 KB
testcase_18 AC 26 ms
4,948 KB
testcase_19 AC 18 ms
4,576 KB
testcase_20 AC 26 ms
5,096 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 27 ms
5,084 KB
testcase_32 AC 14 ms
4,380 KB
testcase_33 AC 15 ms
4,496 KB
testcase_34 AC 25 ms
5,020 KB
testcase_35 AC 1 ms
4,380 KB
testcase_36 AC 27 ms
5,052 KB
権限があれば一括ダウンロードができます

ソースコード

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;
  LL rK=N-K;
  LL pibot;
  if(rK*2>=N) pibot=0;
  else pibot=(N-rK-rK-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