結果

問題 No.1391 ±1 Abs Sum
ユーザー ocvret_ocvret_
提出日時 2021-02-13 17:28:29
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 836 bytes
コンパイル時間 1,508 ms
コンパイル使用メモリ 167,204 KB
実行使用メモリ 4,756 KB
最終ジャッジ日時 2023-09-28 02:03:42
合計ジャッジ時間 5,076 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 82 ms
4,728 KB
testcase_12 AC 62 ms
4,380 KB
testcase_13 AC 76 ms
4,376 KB
testcase_14 AC 49 ms
4,376 KB
testcase_15 AC 51 ms
4,376 KB
testcase_16 AC 63 ms
4,380 KB
testcase_17 AC 56 ms
4,380 KB
testcase_18 AC 78 ms
4,480 KB
testcase_19 AC 53 ms
4,380 KB
testcase_20 AC 78 ms
4,648 KB
testcase_21 AC 49 ms
4,376 KB
testcase_22 AC 48 ms
4,388 KB
testcase_23 AC 58 ms
4,416 KB
testcase_24 AC 54 ms
4,420 KB
testcase_25 AC 54 ms
4,380 KB
testcase_26 AC 58 ms
4,380 KB
testcase_27 AC 39 ms
4,380 KB
testcase_28 AC 40 ms
4,376 KB
testcase_29 AC 52 ms
4,380 KB
testcase_30 AC 45 ms
4,380 KB
testcase_31 AC 84 ms
4,588 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 AC 74 ms
4,756 KB
testcase_35 AC 1 ms
4,380 KB
testcase_36 AC 84 ms
4,652 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
// #include<atcoder/all>

using namespace std;
// using namespace atcoder;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0;i < (ll)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007



int main(){
  
  ll n,k;
  cin >> n >> k;
  k = n-k;
  ll r = n-k,x = k,l = 0;
  ll d = 0;
  vector<ll> a(n);
  rep(i,n)cin >> a[i],d += a[i]-a[0];
  for(ll i = r;i < n;i++)d -= (a[i]-a[0])*2;
  r %= n;
  ll res = d;
  if(x == n)x--;
  for(ll i = 1;i < n;i++){
    d -= (n-i-2*x)*(a[i]-a[i-1]);
    d += (i-2*(k-x))*(a[i]-a[i-1]);
    while(abs(a[i]-a[r]) < abs(a[i]-a[l]) && x > 0){
      d += 2*(-abs(a[i]-a[l])+abs(a[i]-a[r]));
      l++;r++;
      l %= n;r %= n;
      x--;
    }
    res = min(res,d);
  }
  cout << res << "\n";
  

  return 0;
}
0