結果

問題 No.1391 ±1 Abs Sum
ユーザー 👑 NachiaNachia
提出日時 2021-02-12 22:08:41
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 608 bytes
コンパイル時間 1,959 ms
コンパイル使用メモリ 198,548 KB
実行使用メモリ 5,348 KB
最終ジャッジ日時 2023-09-27 04:18:22
合計ジャッジ時間 4,245 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 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 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 17 ms
4,376 KB
testcase_15 AC 18 ms
4,548 KB
testcase_16 AC 21 ms
4,684 KB
testcase_17 AC 19 ms
4,468 KB
testcase_18 AC 26 ms
4,844 KB
testcase_19 WA -
testcase_20 WA -
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 28 ms
5,348 KB
testcase_32 AC 15 ms
4,380 KB
testcase_33 AC 17 ms
4,496 KB
testcase_34 WA -
testcase_35 AC 1 ms
4,376 KB
testcase_36 AC 30 ms
5,108 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;
  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;
  rep(i,pibot) ans+=(A[0]-A[i])*2;
  rep(i,K) ans+=(A[i]-A[0])*2;
  rep(i,N) ans+=A[0]-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